最近はプライベートで全くプログラムをやる気も無くなっていて久しぶりに iOSプログラミング。
そこで早速ハマったエラー。
テーブルビューが表示されないので、下記の戻り値を1に設定する。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; }
しかし、NSInternalInconsistencyExceptionエラーとなる。
どうやら、storyboardで画面遷移をしないので、何か矛盾が起きているようだ。
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に見合うidentifierが見つからないようだ。
- (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; }
結局、コメントアウト部分をコメントアウトして、cellのnil判定で初期化する処理を記述。
うまく行ったようです。
やっぱり、テンプレートで作成されたソースコードを良くみないと、自分で記述する場合と、storyboardを使用する場合の記述方法には、今後も気をつけないと。