I’m sure this question has a simple enough answer, but I can’t seem to find it. I have the following code in my UITableViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil)
{
NSLog(@"Cell is nil!");
}
return cell;
}
But in my log output I get
Cell is nil!
and immediately afterwards
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:’
* First throw call stack:
(0x1b68d72 0x135fe51 0x1b68bd8 0xb0e315 0xcb373 0x63578 0xcb1d3 0xcff19 0xcffcf 0xb9384 0xc952e 0x691bc 0x13736be 0x215c3b6 0x2150748 0x215055c 0x20ce7c4 0x20cf92f 0x2171da2 0x1b4b4 0x1be63 0x2c2be 0x2cf9f 0x1f3fd 0x1ac5f39 0x1ac5c10 0x1adeda5 0x1adeb12 0x1b0fb46 0x1b0eed4 0x1b0edab 0x1b28f 0x1ce71 0x253d 0x2465)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Does anyone have any idea why this is happening, and more importantly, how to fix it?
Thanks in advance.
You must create cell if it nil, because method
return unused cell from table view cache.