iOS開發(fā)基礎:UITableView

字號:


    實現UITableView的Controller需要實現 < UITableViewDataSource, UITableViewDelegate > 這兩個代理,具體就是要實現以下兩個方法:
    - (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section{
    return [model getRowCount];
    }
    //返回UITableView的行數
    - (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;
    }
    //呈現UITableView的每一個Cell