錯誤: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中關聯(lián)的類,根據(jù)對應標識創(chuàng)建cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
testCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell" forIndexPath:indexPath];
return cell;
}
如果出現(xiàn)以上的錯誤.有幾種可能:
1.自定義類沒有關聯(lián)sb中的控制器
2.自定義cell沒有設置標識符
3.創(chuàng)建控制器的時候用的是
錯誤: ViewController*vc = [[ViewControlleralloc]init];
正確:UIStoryboard*story = [UIStoryboardstoryboardWithName:@"Main"bundle:nil];
ViewController*vc = [storyinstantiateViewControllerWithIdentifier:@"viewController"];
因為自定義的cell是在sb中,取cell一定要從sb中創(chuàng)建控制器,才能取出sb其中自定義的cell.