UITableViewCell自定义IBOutlet连接崩溃

时间:2013-05-17 08:35:26

标签: ios objective-c xcode

我为一个tablecell做了一个自定义视图,我在单元格中有一些元素,我编写了正确的IBOutlet conenctions等等。

当我不进行任何IBOutlet连接时,我会看到我制作的自定义单元格,所以类和引用都很好。

我与元素建立连接的那一刻,然后编译我得到:

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

.h文件...... 再次,没有连接它工作(但我再也无法修改自定义单元格的整个想法的元素)我在连接到IBOutlet后得到此错误...

我还试图逐个连接1,但它们都在同一范围内发出错误

CustomTableCell.h

#import <UIKit/UIKit.h>

@interface CustomTableCell : UITableViewCell
{
    IBOutlet UIImageView *image;
    IBOutlet UILabel *labelHeader;
    IBOutlet UILabel *labelDescription;
    IBOutlet UIButton *labelButtonPrice;
    IBOutlet UIButton *labelButtonSize;
    IBOutlet UIButton *labelButtonFloor;
    IBOutlet UIButton *labelButtonBeds;
    IBOutlet UIButton *labelButtonBaths;
}

@property (nonatomic) IBOutlet UIImageView *image;
@property (nonatomic) IBOutlet UILabel *labelHeader;
@property (nonatomic) IBOutlet UILabel *labelDescription;
@property (nonatomic) IBOutlet UIButton *labelButtonPrice;
@property (nonatomic) IBOutlet UIButton *labelButtonSize;
@property (nonatomic) IBOutlet UIButton *labelButtonFloor;
@property (nonatomic) IBOutlet UIButton *labelButtonBeds;
@property (nonatomic) IBOutlet UIButton *labelButtonBaths;

@end

CustomTableCell.m

#import "CustomTableCell.h"

@implementation CustomTableCell

@synthesize image;
@synthesize labelHeader;
@synthesize labelDescription;
@synthesize labelButtonPrice;
@synthesize labelButtonSize;
@synthesize labelButtonFloor;
@synthesize labelButtonBeds;
@synthesize labelButtonBaths;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
来自搜索表的

tableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CustomTableCellIdentifier = @"CustomTableCell";

    CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CustomTableCellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell_iPhone" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    //cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
    //cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
    //cell.prepTimeLabel.text = [prepTime objectAtIndex:indexPath.row];

    return cell;
}

现在,当我根本没有连接时,我会看到自定义单元格, 当我建立连接时,它会停止。

1 个答案:

答案 0 :(得分:7)

当您在xib文件中包含自定义单元格并将IBOutlet连接到“文件所有者”对象而不是单元格本身时,可能会发生此问题。

然后,当您尝试使用视图控制器作为xib的文件所有者从xib加载单元格时,它会尝试将image连接到控制器的非现有属性。

尝试检查插座连接并确保它们仅连接到您的电池,而不是任何其他物体

相关问题