自定义UITableViewCell使用情节提要
问题描述:
我正在尝试使用情节提要制作自定义单元。 我已经使用Basic单元测试了我的程序,它工作正常。 现在我创建了一个名为NewsCell的新类,它包含自定义单元格中的不同标签。 我也将这个单元格作为NewsCell的一个子类。小区标识符是“NewsCell”。自定义UITableViewCell使用情节提要
这是的cellForRowAtIndexPath:方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:@"NewsCell"]; //signal : SIGABRT
News *info = [self.news objectAtIndex:indexPath.row];
cell.titreLabel.text = info.titre;
cell.descriptionLabel.text = info.description;
return cell;
}
当我运行我的应用程序,它在第一LIGNE的信号信号SIGABRT崩溃。 我确信我已经在标签和表格视图单元格之间建立了正确的连接。
***由于未捕获的异常'NSInternalInconsistencyException',终止应用程序,原因:'NIB数据无效'。
答
我有同样的问题。事实证明,我在Storyboard文件的Interface Builder文档窗格中选中了“Use Autolayout”。这会在iOS 5上运行时引发“无效的NIB”错误,因为自动布局仅在iOS 6上受支持。
答
您尚未为单元创建实例。尝试为单元格创建实例。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:@"NewsCell"]; //signal : SIGABRT
if (cell == nil) {
cell = [[[NewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
News *info = [self.news objectAtIndex:indexPath.row];
cell.titreLabel.text = info.titre;
cell.descriptionLabel.text = info.description;
return cell;
}
它不起作用,我试图创建自定义单元格,而不是基本单元格。 – Ali
故事板(及其模板单元)不再需要'cell == nil' /创建零件。 – Thilo