iOS開發(fā)基礎(chǔ):UITableView

字號(hào):


    實(shí)現(xiàn)UITableView的Controller需要實(shí)現(xiàn) < UITableViewDataSource, UITableViewDelegate > 這兩個(gè)代理,具體就是要實(shí)現(xiàn)以下兩個(gè)方法:
    - (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的每一個(gè)Cell