jjzjj

iOS6 崩溃 : this class is not key value coding-compliant for the key

coder 2024-01-12 原文

<分区>

我在 iOS6 设备而非 iOS 7 设备上运行时发生崩溃。我有一个带有 xib LanguageCell.xib 的自定义 UITableViewCell。它有 2 个标签、一个按钮和一个 View 。我有一个 LanguageCell 类,其中有 4 个 IBOutlets:

@interface LanguageCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *titleLbl;
@property (strong, nonatomic) IBOutlet UIButton *buyButton;
@property (strong, nonatomic) IBOutlet UILabel *saleLbl;
@property (strong, nonatomic) IBOutlet UIView *separatorLine;

我已将所有 4 个 View 连接到它们的属性,因此连接 Pane 如下所示:

当我运行应用程序时,加载此表时发生崩溃:

*** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<LanguageCell 0x1f5160c0> setValue:forUndefinedKey:]: this class
is not key value coding-compliant for the key buyButton.'

为什么我在 iOS6 而不是 iOS7 上遇到这个问题?

编辑: 我应该补充一点,自定义类在 xib 上设置正确

编辑 2: 当我清除所有 IB 连接并运行代码时,行 if ([currentObject isKindOfClass:[LanguageCell class]]) 在应该为真时返回 false,因此 cell仍然是 nil

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

    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LanguageCell" owner:nil options:nil];
        for (id currentObject in topLevelObjects)
        {
            if ([currentObject isKindOfClass:[LanguageCell class]])
            {
                cell = (LanguageCell *)currentObject;
                break;
            }
        }
    }

我在我的应用程序中对其他 3 个表使用了完全相同的代码,并且工作正常。我不明白为什么这个问题给我带来了问题。

有关iOS6 崩溃 : this class is not key value coding-compliant for the key的更多相关文章

随机推荐