1

UITableView当我将 segue 拖到要推送的另一个视图控制器时,出现以下错误。

"invalid nib registered for identifier (Cell) - nib must contain exactly one top level object which must be a `UITableViewCell` instance"

我的故事板上有一个UITableView。我通过情节提要在 UITableView 中放入了两个静态行。我通过情节提要为这些行提供了“单元格”的单元格标识符。

这是我的cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    [cell.textLabel setFont:[UIFont fontWithName:@"GothamRounded-Light" size:18]];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 13, 300, 30)];
    label.textColor = [UIColor statLightBlue];
    [label setFont:[UIFont fontWithName:@"Rounded-Light" size:18]];
    [cell.contentView addSubview:label];

    if(indexPath.row == 0){
        label.text = @"Credit Card"; // man profile
        cell.imageView.image = [UIImage imageNamed:@"CreditCardIcon.png"];    
    } else if (indexPath.row == 1) {
        label.text = @"Promotion Code"; // credit card
        cell.imageView.image = [UIImage imageNamed:@"PromoCodeIcon.png"];
    }

    return cell;
}

在这一点上,一切都很好。但这是我所做的导致上述错误的原因:

如果我控制从故事板中的第一个单元格拖动UITableView到创建 segue 的任何其他随机视图,则会导致上述错误。如果我删除所说的 segue,错误就会消失。

关于我做错了什么的任何线索?

4

3 回答 3

0

问题是如果你在 IB 或恢复 ID 中设置标识符,你给“CELL”并且没有“Cell”也要仔细检查,你必须设置的标识符在“属性检查器”中

于 2013-11-06T17:58:16.573 回答
0

好的,问题是我在属性检查器中选择了动态单元格,但是 cellForRowAtIndex 中的代码错误。

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

{

UITableViewCell *cell = [super tableView:tableView
                   cellForRowAtIndexPath:indexPath];


[cell.textLabel setFont:[UIFont fontWithName:@"Rounded-Light" size:18]];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 13, 300, 30)];
label.textColor = [UIColor statLightBlue];
[label setFont:[UIFont fontWithName:@"Rounded-Light" size:18]];
[cell.contentView addSubview:label];


if(indexPath.row == 0){
    label.text = @"Credit Card"; // man profile
    cell.imageView.image = [UIImage imageNamed:@"CreditCardIcon.png"];

} else if (indexPath.row == 1) {
    label.text = @"Promotion Code"; // credit card
    cell.imageView.image = [UIImage imageNamed:@"PromoCodeIcon.png"];
}

return cell;

}
于 2013-11-06T20:49:51.427 回答
-1

I got the similar error using storyboard. Fix it by changing Table View's "Prototype Cells"@"Attributes inspector" to 1.

于 2014-01-23T13:35:09.847 回答