NSInternalInconsistencyException

最近はプライベートで全くプログラムをやる気も無くなっていて久しぶりに iOSプログラミング。
そこで早速ハマったエラー。

テーブルビューが表示されないので、下記の戻り値を1に設定する。

[c]
– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
[/c]

しかし、NSInternalInconsistencyExceptionエラーとなる。
どうやら、storyboardで画面遷移をしないので、何か矛盾が起きているようだ。
[bash]
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’
[/bash]

以下のコメントアウト部分でエラーとなっていた。
indexPathに見合うidentifierが見つからないようだ。
[c]
– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell…
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"セル";
return cell;
}
[/c]

結局、コメントアウト部分をコメントアウトして、cellのnil判定で初期化する処理を記述。
うまく行ったようです。

やっぱり、テンプレートで作成されたソースコードを良くみないと、自分で記述する場合と、storyboardを使用する場合の記述方法には、今後も気をつけないと。

This entry was posted in Objective-C, 技術情報. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です