2012年4月10日火曜日

UITableView dataSource must return a cell


*** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], ...
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

UITableViewのdelegateメソッド-tableView:cellForRowAtIndexPath:がnilを返すと発生します。
セルオブジェクト再利用のために次のようにインスタンスを取得しますが、
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Storyboardで設定したCellのidentifierとCellIdentifierが一致していないとnilとなります。

プロトタイプセルを使用していない場合はメソッドでCellインスタンスを作成します。
プロトタイプセルを使用している場合はStroyboardのidentifierが正しく設定されているか確認します。

0 件のコメント: