[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 storyboar

iOSアプリ開発にて、UITableView でエラー発生。

■ エラーメッセージ

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’

■ 解決方法

indexPathに対応するCellのUIが取得できないので、indexPath指定せずに、後で値を取得するように修正すればOKです。

//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; //これだと実行時エラー
 
    static NSString *CellIdentifier = @"Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

【参考】:UITableView dequeueReusableCellWithIdentifier:forIndexPath: でのアサーション #iOS #Objective-C – Qiita はてなブックマーク - UITableView dequeueReusableCellWithIdentifier:forIndexPath: でのアサーション #iOS #Objective-C - Qiita