使用Storyboard自定义UITableViewCell [英] Custom UITableViewCell using Storyboard
问题描述
我正在尝试使用故事板制作自定义单元格。
我用Basic单元测试了我的程序并且它有效。
现在我已经创建了一个名为NewsCell的新类,它包含自定义单元格中的不同标签。
我还将单元格作为NewsCell的子类。单元格标识符为NewsCell。
I'm trying to make a custom cell using storyboard. I have tested my program with Basic cells and it worked. Now I'have created a new class that I named NewsCell, which is containing the different Labels in the custom cell. I have also made the cell a subclass of NewsCell. The cell identifier is "NewsCell".
这是cellForRowAtIndexPath:方法:
This is the cellForRowAtIndexPath: method:
- (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;
}
当我运行我的应用程序时,它首先崩溃信号信号SIGABRT LIGNE。
我确定我在标签和表格视图单元格之间建立了正确的连接。
When I run my app, it crashes with a signal signal SIGABRT at the first ligne. I'm sure that I've made the right connections between Labels and the table view cell.
***终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:'NIB数据无效。'
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The NIB data is invalid.'
推荐答案
<我遇到了同样的问题。原来,我在Storyboard文件的Interface Builder Document窗格中检查了Use Autolayout。这会在iOS 5上运行时抛出无效的NIB错误,因为仅在iOS 6上支持自动布局。
I had the same problem. It turned out that I had checked "Use Autolayout" in the Interface Builder Document pane of the Storyboard file. This throws the "invalid NIB" error when running on iOS 5 because autolayout is only supported on iOS 6.
这篇关于使用Storyboard自定义UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!