LoginSignup
19
19

More than 5 years have passed since last update.

UITableView dequeueReusableCellWithIdentifier:forIndexPath: でのアサーション

Last updated at Posted at 2012-10-27

2012-09-24 22:52:24.634 xxx[55320:c07] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
2012-09-24 22:52:24.635 xxx[55320:c07] *** 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指定せずに、後で値を取るようにすると良いらしい。

//    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];
    }
19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19