7
Go to list of users who liked
7
More than 5 years have passed since last update.
TableViewControllerのサブクラスつくったら’unable to dequeue a cell with identifier Cell’という実行時エラーが出た。
Last updated atPosted at 2013-10-13
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;}
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme