そのため、カスタムUITableViewCells
(ストーリーボードで作成) があり、セルを文字通り割り当て、初期化しないと、アプリがクラッシュします。ただし、それらはカスタムセルであるため、割り当て/初期化する方法がわかりません。
このコードはクラッシュします:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCells *cell = (TableViewCells *)[tableView dequeueReusableCellWithIdentifier:@"TableViewCellsID"];
return cell;
}
これでコンソールに出力されます:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
これは、まだセルが割り当てられていないため、クラッシュすることを意味すると理解していますが、割り当てようとすると、セル スタイルを指定する必要があります。
したがって、次のようにセルをビルドすると、クラッシュしません。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCells *cell = (TableViewCells *)[tableView dequeueReusableCellWithIdentifier:@"TableViewCellsID"];
if (cell == nil)
cell = [[TableViewCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableViewCellsID"];
return cell;
}
問題は、動作するコード (2 番目のセット) であり、UITableViewStyle
. 私の知る限り、UITableViewStyleCustom はありません。
どんな助けでもいただければ幸いです。