Wei Du Wei Du - 3 months ago 46
Objective-C Question

NSInternalInconsistencyException when customize tableview cell in storyboard

I want use storyboard to create custom

UITableViewCell
, and when I run my program, it crashed, here is the log:


*** Terminating app due to uncaught exception'NSInternalInconsistencyException', reason: 'UITableView (; animations = { position=; }; layer = ; contentOffset: {0, 0}; contentSize: {375, 304.23076923076923}>) failed to obtain a cell from its dataSource ()'


and I just get my tableviewcell using its identifier:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ThemeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"themecell"];

return cell;
}


Here are some constraints in my storyboard:

constraints

Answer

1) make sure you are using the correct tableviewcell identifier. 2) Then, do this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ThemeCell *cell = (ThemeCell *)[tableView dequeueReusableCellWithIdentifier:@"themecell"];
    return cell;
}
Comments