[Objective-C][iOS] 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
During iOS app development, an error occurred with UITableView.
■ Error Message
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'
■ Solution
Since the Cell UI corresponding to indexPath cannot be obtained, you can fix this by not specifying indexPath and retrieving the value later.
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; //This causes runtime error
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
【Reference】:UITableView dequeueReusableCellWithIdentifier:forIndexPath: でのアサーション #iOS #Objective-C - Qiita
That’s all from the Gemba.