Storyboard中自定義cell遇到的問題

錯誤: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.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容