我試圖使用自定義UITableViewCell
構建我的應用程序。這是我UIViewController
,增加了viewCell
表的代碼:添加自定義UITableViewCell崩潰模擬器
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"------- Tableview --------");
static NSString *myIdentifier = @"MyIdentifier";
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:myIdentifier];
if(cell == nil) {
NSArray *cellView = [[NSBundle mainBundle] loadNibNamed:@"tblCellView" owner:self options:nil];
cell = [cellView objectAtIndex:0];
}
[cell setLabelText:[NSString stringWithFormat:@"indexpath.row: %d", indexPath.row]];
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:myIdentifier] autorelease];
cell.textLabel.text = @"bös";
return cell;
}
如果我去掉上面的「返回細胞」行返回一個普通UITableViewCell
沒有任何錯誤,但只要我嘗試執行我定製單元它崩潰與此錯誤:
------- Tableview -------- 2010-04-23 11:17:33.163 Golf[26935:40b] * Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-984.38/UITableView.m:4709 2010-04-23 11:17:33.164 Golf[26935:40b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 2010-04-23 11:17:33.165 Golf[26935:40b] Stack: (
...
我已經配置.xib文件應與適當的插座應該。和UITableViewCell的標識符對應於名稱即時嘗試從NSBundle加載
試用鑄造(MyTableCell *) – willcodejavaforfood 2010-04-23 11:32:47
不要忘記導入自定義單元格英寸m文件並與自定義單元格綁定,並檢查數據源的tableview代表。 – 2012-09-14 08:37:39