Мне нужно нарисовать изображение в ячейке таблицы.До сих пор я не смог получить правильную ссылку на UIImageView после того, как я создал представление и назначил его ячейке.Та же процедура работает для UILabel, например.
Я не могу понять, что я делаю неправильно.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UIImageView *imageView;
UILabel *title;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
// Setup title
title = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)] autorelease];
title.tag = 1;
[cell.contentView addSubview:title];
// Setup image
UIImageView* imageView = [[[ UIImageView alloc] initWithFrame:
CGRectMake(50, 0, 50, 50)] autorelease];
imageView.tag = 2;
[cell.contentView addSubview:imageView];
} else {
// Get references to cell views
title = (UILabel *)[cell.contentView viewWithTag:1];
imageView = (UIImageView *)[cell.contentView viewWithTag:2];
}
NSLog(@"%@", [title class]); // UILabel
NSLog(@"%@", [imageView class]); // CRASH! EXC_BAD_ACCESS
return cell;
}