【问题标题】:'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: ...' with name'NSInternalInconsistencyException',原因:'无法在包中加载 NIB:...' 带有名称
【发布时间】:2014-06-19 08:40:59
【问题描述】:

我正在尝试向 tableView 添加自定义单元格

我首先创建了一个带有 2 个标签“名称”和“描述”的 xib 文件,我已将其链接到控制器“customCellAchievementController”

当我尝试创建 tableView 时似乎找不到笔尖

知道这会在哪里失败吗?

我已将我的 xib 的类重新定义为控制器,我已将标识符更改为我在代码中使用的标识符,我已检查 xib 文件是否处于构建阶段/复制捆绑资源一切似乎都很好,我真的不明白......

这是我的代码

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [achievement count];

}

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

static NSString *customCellIdentifier = @"CustomCell";

CustomCellAchievementController *cell = (CustomCellAchievementController *)[tableView dequeueReusableCellWithIdentifier:customCellIdentifier];

if(cell==nil){

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

cell.name.text= [achievement objectAtIndex:indexPath.row];
cell.description.text = [description objectAtIndex:indexPath.row];

return cell;
}

【问题讨论】:

  • 您的 nib 文件的名称是什么?
  • 您是否在 xcode 之外重命名了您的 xib?
  • 您甚至可以检查 nib 文件是否已添加到 Xcode 目标的“构建阶段”选项卡的“复制包资源”部分下的包中

标签: ios objective-c uitableview


【解决方案1】:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *customCellIdentifier = @"CustomCell";
CustomCellAchievementController *cell=[tableView dequeueReusableCellWithIdentifier: customCellIdentifier];
if (cell==nil)
{
    NSArray *arr1=[[NSBundle mainBundle]loadNibNamed:@"CustomCellAchievementController" owner:nil options:nil ];
    for(UIView *vie in arr1)
    {
        if([vie isKindOfClass:[UITableViewCell class]])
        {
            cell=(CustomCellAchievementController*)vie;
            cell.name.text= [achievement objectAtIndex:indexPath.row];
            cell.description.text = [description objectAtIndex:indexPath.row];

        }
    }
}

return cell;

}

【讨论】:

  • 如果你需要修改我改变一些东西试试这个
【解决方案2】:

检查您的网点。奥特莱斯应与班级而不是班级所有者关联。
详情请参阅Loaded nib but the view outlet was not set - new to InterfaceBuilder

【讨论】:

    猜你喜欢
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    相关资源
    最近更新 更多