11

由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 buttonOfFirstView 的键值编码不兼容。”

为什么我会收到此错误?我正在尝试通过 XIB 制作一个表格单元格。添加此代码后,它会引发上述异常。

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

    static NSString *CellIdentifier = @"MyCell";

    MyTableViewCell *cell = (MyTableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        NSArray *arrayCellXib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" 
                                                              owner:self 
                                                            options:nil];

....
} 
.....

return cell;
}

如何解决?

4

5 回答 5

49

检查您在 XIB 中对网点的引用,其中一个可能引用了不再存在的属性 (buttonOfFirstView)

于 2012-05-31T06:42:09.927 回答
2

将 File's Owner 类设置为NSObject并将UITableViewCell类设置为您在 XIB 中的自定义类。它将解决问题。

于 2014-10-04T19:48:21.953 回答
1

这正是与您的情况下的关键 buttonOfFirstView 相关的问题。如果它是一个按钮,它可能在您的任何 xib 中连接错误

于 2012-05-31T06:42:47.183 回答
0

退出 iOS 模拟器。确保保存项目,然后退出 xCode 并重新启动,一切都会好起来的。我这样做了,它对我有用。那就是如果其他一切都正确连接。

于 2013-08-08T19:55:30.070 回答
0

你需要清理你的项目:转到 Product -> Clean

这对我有用

于 2013-09-03T17:45:54.963 回答