无法在捆绑中加载NIB! TableView中的海关单元

时间:2014-05-26 07:51:15

标签: ios objective-c uitableview

我的tableView有问题。我想在tableView中有6个不同的单元格。

所以,在viewDidLoad,我有这个:

[_tableView registerNib:[UINib nibWithNibName:@"KBCategoriePriceTableViewCell" bundle:nil]
 forCellReuseIdentifier:@"KBCategoriePriceTableViewCell"];

对于其他单元格,它是相同的代码,并在cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    NSString* nameCell = [array objectAtIndex:indexPath.row];

    if([nameCell isEqualToString:CELL_VIEW_CATEGORY_PRICE]){
        KBCategoriePriceTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"KBCategoriePriceTableViewCell"];
        [cell setBackgroundColor:[[receive category] colorBackground]];
        [cell.buttonCategorie setTitle:@"" forState:UIControlStateNormal];
        [cell.buttonCategorie setEnabled:NO];
        [cell.buttonCategorie setImage:[UIImage imageNamed:[[receive category] imageName]]forState:UIControlStateNormal];
        [cell.buttonDevise setTitle:[[receive devise] symbole] forState:UIControlStateNormal];
        [cell.buttonCategorie setEnabled:NO];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
}
}

但是,当我启动我的应用程序时,它崩溃了!出现此错误消息:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/jean-nicolasdefosse/Library/Application Support/iPhone Simulator/7.1/Applications/20031DF6-D297-44D0-9D67-4AD3439D85F7/KillTheBill.app> (loaded)' with name 'KBCategoriePriceTableViewCell''

我不明白为什么它不起作用。

我删除了引用并添加了项目中的文件,我检查了目标,自定义单元格KBCategoriePriceTableViewCell在“xib”中具有标识符:KBCategoriePriceTableViewCell

请帮助我!

4 个答案:

答案 0 :(得分:2)

错误消息表示您的项目中没有名为KBCategoriePriceTableViewCell.nib的文件。

此外,您应该始终返回tableView:cellForRowAtIndexPath:

中的单元格

答案 1 :(得分:0)

您需要加载自定义单元格,如下面的代码..

您还需要检查nil条件,因为最初我们不需要加载任何自定义单元格。

static NSString *cellidentifier=@"cell";
    KBCategoriePriceTableViewCell *cell=(KBCategoriePriceTableViewCell *)[explortableview dequeueReusableCellWithIdentifier:cellidentifier];
    if (cell==nil)
    {
        [[NSBundle mainBundle]loadNibNamed:@"KBCategoriePriceTableViewCell" owner:self options:nil];
        cell=self.categoriesCell; //categoriesCell is reference of KBCategoriePriceTableViewCell in which you connected at xib

    }

希望它可以帮助你......!

答案 2 :(得分:0)

请勿在{{1​​}}。

中加载Nib文件

您可以使用以下代码:

viewDidLoad

这里,- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellidentifier=@"KBCategoriePriceTableViewCell"; KBCategoriePriceTableViewCell *cell=(KBCategoriePriceTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier]; if(cell==nil){ NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KBCategoriePriceTableViewCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } cell.lbl_name.text=@"Meeting"; return cell; } 是第一个可以加载动态单元格的单元格。

答案 3 :(得分:0)

小心不要使用initWithXib来调用原型单元,因为它会崩溃

相关问题