我将UIImageView添加到CustomCell(UITableViewCell的子类)。
但是,当我在CustomCell设置ImageView的图像,
应用程序冲突与日志消息:
[CustomCell setImageView:]:无法识别的选择器
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomCell setImageView:]: unrecognized selector sent to instance 0x10912d990'
我有这样的代码。
的ViewController
@property (nonatomic, strong) UITableView* tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 508)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifer = @"Cell";
CustomCell* cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifer];
if (cell == nil) {
cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
}
switch (indexPath.section) {
case 0:
switch (indexPath.row) {
case 0:
cell.imageView.image = [UIImage imageNamed:@"hello.jpg"];
break;
default:
break;
}
default:
break;
}
return cell;
}
CustomCell
@property (nonatomic, strong) UIImageView* imageView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 310, 170)];
[self addSubview:self.imageView];
}
return self;
}
你有什么想法,将图像添加到ImageView的上customCell?
谢谢。
穿上这条线调试点,看看它打它:' cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer]; ' – chuthan20
使您的CustomCell成为支持setImageView方法的东西的子类。 –
尝试在viewDidLoad中注册自定义单元格:self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@“CustomCell”]; –