NSUnknownKeyException setValue:forUndefinedKey: [duplicate]

泪湿孤枕 提交于 2019-11-26 18:26:47

问题


This question already has an answer here:

  • Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error? 67 answers

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key buttonOfFirstView.'

Why do I get this error? I am trying to make a table cell though XIB. After I add this code it throws the above exception.

- (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;
}

How to resolve it?


回答1:


Check your references of your outlets in your XIB, one of them is probably referencing a property (buttonOfFirstView) that does not exist anymore




回答2:


Set File's Owner class to NSObject and set UITableViewCell class to your custom class in XIB. It will solve the issue.




回答3:


This is exactly an issue related to the key buttonOfFirstView in your case.If it is a button it may be connected wrongly in any of your xibs




回答4:


Quit the iOS simulator. Make sure you save the project and then quit xCode and restart and everything will be fine. I did that and it worked for me. that's if everything else is hooked up correctly.




回答5:


you need to clean your project: go to Product -> Clean

this works for me



来源:https://stackoverflow.com/questions/10828608/nsunknownkeyexception-setvalueforundefinedkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!