您的位置:首页 > 产品设计 > UI/UE

UITableView 的一个常见错误'unable to dequeue a cell with identifier Cell - must register a nib or a class f

2014-08-07 17:37 369 查看
运行,出错了,关键性提示如下:

'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

看起来是单元格的ID有问题。

因为我们这里用的是动态单元格了,因此这个单元格必须有一个ID。这里,我设置该单元格的ID为

Cell。

然后,编辑以下函数的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

switch (indexPath.row) {
case 0:
cell.textLabel.text=@"渝开发  000514";
break;
case 1:
cell.textLabel.text=@"我的第一桶金";
break;
default:
break;
}

// Configure the cell...

return cell;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐