我在Storyboard中添加了一个TableViewController,并将其类型更改为继承UITableViewController的自定义类。 我还在故事板中添加了一些单元格。 (不是自定义的,基本的UITableViewCells) 现在我想以编程方式修改这些单元格(如有条件地添加披露指示符)。所以,我做了我的班采取的UITableViewDelegate,但是当我尝试以编程方式修改我的单元格的文本,我得到这个错误:无法从其dataSource中获取单元格 - 故事板和代码
NSInternalInconsistencyException : failed to obtain a cell from its dataSource
下面是代码:
@interface MyTableViewController() <UITableViewDelegate>
@end
@implementation MyTableViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"test";
return cell;
}
@end
在我的故事板,在引用出口,我正确地有dataSource和委托链接到表视图。 我在这里错过了什么?感谢您的帮助
您正在调用'[tableView cellForRowAtIndexPath:indexPath]'?这不是要调用的方法。调用'UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@“someCellID”forIndexPath:indexPath];' – Larme
对于您的表格视图内容,您使用的是动态原型还是静态单元格? –
@Larme谢谢你的回复。我尝试在我的故事板中设置标识符“TestCell”,并用'dequeueReusableCellWithIdentifier'替换了'cellForRowAtIndexPath',但现在我得到这个错误:'无法使标识符TestCell出队 - 必须为标识符注册一个笔尖或类,连接故事板中的原型单元格 – Someday