我为表格单元制作了一个自定义视图,单元格中有一些元素,我编写了正确的 IBOutlet 连接等。
当我不进行任何 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 接 1 的连接,但它们都在同一范围内给出错误
自定义表格单元格.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
自定义表格单元.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
搜索表中的表视图
- (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;
}
现在,当我根本没有连接时,我会看到自定义单元格,当我建立连接时它会停止。