LoginSignup
0
0

More than 5 years have passed since last update.

UITableViewControllerを継承してUITableViewを作る

Posted at

デフォルトで生成されるコードだとcellForRowAtIndexPathで例外が発生して動きません。

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'

下記のように修正すると動きます。。。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = @"hogehoge";

    return cell;
}

[参考]
UITableViewでのNSInternalInconsistencyException

0
0
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
0
0