我正在尝试显示我在 InterfaceBuilder 中制作的两个不同的 UITableViewCell,但是我收到了这个错误。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
我创建了两个新的 nib,我已将文件所有者类更改为我试图在其中显示它们的 UITableViewController,并使用 IBOutlets 等将它们连接起来。
错误发生在TableView:cellForRowAtIndexPath内部,这就是我对该类的方法的样子
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(indexPath.section == 0) {
// Manufactures --->
if (indexPath.row == 0) {
cell = nil;
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CodeSearchTextCell" owner:self options:nil];
cell = codeSearchTextCell; //Loads tableviewcells with custome xib-cell that I have made in Interface builder
self.codeSearchTextCell = nil;
}
codeTextField.layer.borderColor = [UIColor lightGrayColor].CGColor;
codeTextField.layer.borderWidth = 0.5f;
cell.userInteractionEnabled = NO;
}
else if (indexPath.row == 1) {
cell = nil;
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CodeSearchCell" owner:self options:nil];
cell = codeSearchCell; //Loads tableviewcells with custome xib-cell that I have made in Interface builder
self.codeSearchCell = nil;
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //adds disclosure indicator
cell.userInteractionEnabled = YES;
}
}
return cell;
}
我不确定我做错了什么,但是当我将断点放在最后一行时,我可以清楚地看到我返回的单元格返回没有任何价值。
任何帮助将不胜感激。