0

我已经分类UITableViewCellMyCell并试图让表格显示。我总是收到消息:

exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:

的代码tableView:cellForRowAtIndexPath如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
MyCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
MyCell* theCell = (MyCell *)cell;
UILabel* lab = theCell.theLabel;
lab.text = @"This is the label text";
return cell;
}

我已在笔尖中将 CellIdentifier 设置为“Cell”。我以为我要返回一个带有最后一行的单元格?我哪里错了?

4

1 回答 1

1

您的单元格必须为零。你应该像白色一样:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    MyCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"MyCell"].lastObject;
    }
    // Configure the cell...
    UILabel* lab = cell.theLabel;
    lab.text = @"This is the label text";
    return cell;
}
于 2012-12-18T20:52:39.433 回答