我已将 UITableViewCell
子类化为 MyCell
并尝试显示表格。我总是收到消息:
异常“NSInternalInconsistencyException”,原因:“UITableView dataSource 必须从 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;
}
我已将 Nib 中的 CellIdentifier 设置为“Cell”。我以为我正在返回带有最后一行的单元格? 我哪里错了?
最佳答案
您的单元格必须为零。你应该将类似的白色设置为:
- (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;
}
关于ios - 具有自己的 Nib 和 UITableViewCell 子类的 TableViewCell 设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13941167/