0
所以我有自定義UITableViewCells
(與故事板),並且當我沒有字面上分配,初始化單元格,應用程序崩潰。但是,由於它們是自定義單元格,我不知道如何分配/初始化它們。自定義UITableViewCells Alloc Problrm
此代碼崩潰:
- (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;
}
的問題是,工程(第二組)的代碼,需要我設置UITableViewStyle
。據我所知,沒有UITableViewStyleCustom。
任何幫助,將不勝感激。
我明白爲什麼它的崩潰,但我需要一種方式來創建一個單元,而不指定樣式 – Andrew
爲什麼會投票?在代碼中提到的問題是崩潰,我提供了原因。現在爲第二個查詢我會給出答案。 – rishi
如果你對自定義單元格alloc感興趣,那麼你可以檢查這個線程 - http://stackoverflow.com/questions/1754036/how-to-make-custom-tableviewcell-with-initwithstyle-after-3-0 – rishi