美文网首页
Storyboard中自定义cell遇到的问题

Storyboard中自定义cell遇到的问题

作者: 策马鞭程 | 来源:发表于2016-04-28 23:28 被阅读842次

错误:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier testCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

tableview:cellForRowAtindexPath:方法从缓存池中找cell,如果没有找到,它会到sb中关联的类,根据对应标识创建cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

testCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell" forIndexPath:indexPath];

return cell;

}

如果出现以上的错误.有几种可能:

1.自定义类没有关联sb中的控制器

2.自定义cell没有设置标识符

3.创建控制器的时候用的是

错误: ViewController*vc = [[ViewControlleralloc]init];

正确:UIStoryboard*story = [UIStoryboardstoryboardWithName:@"Main"bundle:nil];

ViewController*vc = [storyinstantiateViewControllerWithIdentifier:@"viewController"];

因为自定义的cell是在sb中,取cell一定要从sb中创建控制器,才能取出sb其中自定义的cell.

相关文章

网友评论

      本文标题:Storyboard中自定义cell遇到的问题

      本文链接:https://www.haomeiwen.com/subject/hgmhrttx.html