'NSInternalInconsistencyException',原因:'NIB数据无效。'对于CustomCell

问题描述 投票:3回答:5

我得到的错误就像 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The NIB data is invalid.'

对于iOS 5.0,即使我取消选中AutoLayout并为customcell的所有iOS版本提供部署支持。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        static NSString *CustomCellIdentifier = @"GroupListCell";

        GroupListCell *cell = (GroupListCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];

            if (cell == nil)
            {
                NSArray *nib;

                if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
                {
                    nib= [[NSBundle mainBundle] loadNibNamed:@"GroupListCell" owner:self options:nil];
                }
                else{
                    nib= [[NSBundle mainBundle] loadNibNamed:@"GroupListiPhoneCell" owner:self options:nil]; // sigabrt
                }
                // cell implementation code..
           }
}

此代码适用于iOS6.0但不适用于iOS 5.0。 问题是什么?我错过了什么。

iphone ios xcode ios5 ios6
5个回答
15
投票

使用下图中设置的值检查nib文件

检查UILabel UIButton文本


4
投票

一段时间AutoLayout也可能导致问题。所以拿xib文件 - 督察窗格 - un tick autolayout


2
投票

最后我发现了这个问题。

我的单元格中有一个textview,即使Text属性定义为“Plain”,它也归因于文本。它在“平原”中没有改变。因为手动更改文本并使用enter关键字转到下一行。在内部,它被视为“归属”。

因此,检查TextView的text属性2次。 :)


1
投票

您的案例中可能缺少用于提取单元格的代码。希望以下更正的代码有效。

if (cell == nil)
            {
                NSArray *nib;

                if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
                {
                    nib= [[NSBundle mainBundle] loadNibNamed:@"GroupListCell" owner:self options:nil];

                  cell = [nib objectAtindex:0]; 
                }
                else{
                    nib= [[NSBundle mainBundle] loadNibNamed:@"GroupListiPhoneCell" owner:self options:nil]; // sigabrt
                  cell = [nib objectAtindex:0];
                }
                // cell implementation code..
           }

1
投票

对于较低版本的iOS 6,它可能会发生。

解决这个问题

然后选择故事板

File Inspector-> Interface Builder Document取消选中Use Auto Layout

File Inspector-> Localization取消选中Base并检查English

© www.soinside.com 2019 - 2024. All rights reserved.