此类不是键标签的键值编码兼容

s_k*_*les 4 objective-c uitableview ios nsunknownkeyexception

我正在使用一个自定义UITableViewCell,它已经有一些完全有效的UI元素.但是,我只是尝试为它们添加两个标签,当我连接插座并调用时cell.label.text = @"text";,程序崩溃并出现错误:

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

我检查了是否有任何没有元素的连接,但没有.当除了新UI元素之外的所有内容都添加到单元格时,该应用程序完全有效 就在我添加应用程序崩溃的新UI元素时.这是什么问题?

自定义单元类.h

#import <UIKit/UIKit.h>

@interface FeedTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *profileImage;
@property (weak, nonatomic) IBOutlet UITextView *questionTextView;
@property (weak, nonatomic) IBOutlet UIButton *usernameButton;
@property (weak,nonatomic) IBOutlet UILabel * likesLabel;
@end
Run Code Online (Sandbox Code Playgroud)

喜欢的标签是问题的出路

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

    FeedTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[FeedTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }     
    cell.likesLabel.text = @"text";
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

电池的插座连接:

在此输入图像描述

小智 10

在花费太多时间之后,"清理项目"为我解决了同样的神秘问题.user1851782提到这是他的最终评论,但我想我会强调这一点.使用Xcode 6.