如果既沒有在TableViewController中使用代碼的方式注冊:
[self.tableView registerClass: [CustomTableViewCell class]
forCellReuseIdentifier: CellTableIdentifier];
也沒有在storyboard或nib中的視圖Cell的Identity Inspector->Custom Class對應(yīng)Cell:
identity inspector
實(shí)現(xiàn)tableView:cellForRowAtIndexPath:時对蒲,調(diào)用以下方法會在運(yùn)行時報(bào)錯:
*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'***
......
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"Cell" forIndexPath:indexPath];
......
這時應(yīng)該采用沒有IndexPath參數(shù)這種:
......
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:
UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
......