【发布时间】:2013-04-05 09:14:20
【问题描述】:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
cell.cellDate.text=@"date";
cell.cellDescription.text =@"Description";
cell.cellImageview.image = [UIImage imageNamed:@"sample.png"];
cell.cellTitle.text = @"Title";
NSLog([cell Description]);
return cell;
}
NSLog([cell Description]);
返回空值
以上是我的方法它给出以下错误: 这里
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'UITableView 数据源 必须从 tableView 返回一个单元格:cellForRowAtIndexPath:'
【问题讨论】:
-
在内部分配您的自定义单元格 if (cell == nil) {}
-
@vitality 向您展示的内容是正确的。底线是您需要初始化一个新单元格。所以在
(cell==nil)之后,只需插入这一行:cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
标签: ios ipad uitableview