ios開發(fā)基礎(chǔ):uitableview

字號:


    實現(xiàn)uitableview的controller需要實現(xiàn) < uitableviewdatasource, uitableviewdelegate > 這兩個代理,具體就是要實現(xiàn)以下兩個方法:
    - (nsinteger)tableview:(uitableview *)tableview
    numberofrowsinsection:(nsinteger)section{
    return [model getrowcount];
    }
    //返回uitableview的行數(shù)
    - (uitableviewcell *)tableview:(uitableview *)tableview
    cellforrowatindexpath:(nsindexpath *)indexpath
    {
    static nsstring *cellidentifier = @”cell”;
    uitableviewcell *cell = [tableview
    dequeuereusablecellwithidentifier:cellidentifier];
    if (cell == nil) {
    cell = [[[uitableviewcell alloc]
    initwithframe:cgrectzero
    reuseidentifier:cellidentifier] autorelease];
    }
    nsuinteger row = [indexpath row];
    cell.textlabel.text = [model getnameatindex:row];
    return cell;
    }
    //呈現(xiàn)uitableview的每一個cell