Xcode5.0を使ってSubclassをTableViewControllerに指定して自動で生成したファイルをビルドしたら、シミュレーションでの起動で実行時エラーがでました。(xibは不使用)
二回躓いたので、解決方法をメモします。
出力されたエラーメッセージ
erminating 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 *)tableView:(UITableView |*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
解決方法
自動で生成される以下のコードを変更します。
変更前
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
変更後
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
セルの生成時に、forIndexPath:indexPathを渡さないよう変更しました。
変更後のtableView:cellForRowAtIndexPath:が以下になります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
//cellへの表示する内容を設定する
return cell;
}