0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    CustomCell *cell = (CustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

    }

与 ios 6 模拟器完美配合,但在 ios 5 模拟器上崩溃并出现以下错误:“NSInternalInconsistencyException”,原因:“NIB 数据无效。

苹果改变了什么?

4

1 回答 1

3

这里有一些建议!

如果您使用最新版本的 Xcode(Xcode 4.5 或 4.6)创建此项目,CustomCell 笔尖默认打开自动布局。但是 iOS 5 中没有自动布局。

此外,您的代码在 iOS 5 和 iOS 6 中都是错误的。如果您从笔尖获取单元格,请不要使用loadNibNamed:. 相反,将 nib 注册到表格视图中,使用registerNib:forCellReuseIdentifier:. 现在,当您调用dequeueReusableCellWithIdentifier:nib 时,如有必要,将自动加载。请注意,此 nib 中必须只有一个顶级对象,并且必须是单元格。这是一个愚蠢的规则,但事实就是如此。

于 2013-03-26T00:30:05.830 回答