menuを備えたデフォルトのマスター/詳細テーブルビューがあります。メニューは機能しますが、「+」ボタンを押してアプリに別のセルを追加すると、何らかの理由で次のエラーが発生します。
キャッチされていない例外 'NSInternalInconsistencyException' が原因でアプリを終了しています。
何日も解決策を探した
に追加するとviewDidLoad
:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
エラーは発生しませんが、追加されたセルはストーリーボードで構成されたものではなく、詳細ビュー コントローラーを指していません。
プロトタイプ セルの識別子フィールドが入力されていて、*cellIdentifier と同じであるかどうかを何度も確認しました。
私が知っている限りでは、ここで尋ねられた質問と同じ性質のようです。
時間があれば、私がしたことが間違っている理由、または特定のコードを追加する必要がある理由を説明してください。
要求されたコード (どちらも Xcode 5.0.1 によって追加されたデフォルトのコードです):
// Code to add the button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
// Code called when button is pressed:
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
コメントに追加された写真とプロジェクト ファイルもチェックしてください