没有获取“cell.selectedBackgroundView”的视图

时间:2010-12-28 06:17:02

标签: iphone tableview

当我点击它时,我正在尝试更改我的单元格图像。我使用如下代码:

cell.backgroundView = [[[UIImageView alloc] init] autorelease];
cell.selectedBackgroundView = [[[UIImageView alloc] init] autorelease];

cell.textLabel.textColor = [UIColor colorWithRed:162.0/255.0 green:13.0/255.0 blue:20.0/255.0 alpha:1.0];
cell.textLabel.text = [channelCategories objectAtIndex:indexPath.row];

UIImage * backgroundImage = [UIImage imageNamed:@"topAndBottomRow.png"];
UIImage * selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
cell.backgroundColor = [UIColor clearColor];
UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];

cell.backgroundColor = [UIColor clearColor];
((UIImageView *)cell.backgroundView).backgroundColor = [UIColor clearColor];
((UIImageView *)cell.backgroundView).autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
((UIImageView *)cell.backgroundView).image = backgroundImage;
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;

任何人都可以帮我解决这个问题吗? 谢谢。

1 个答案:

答案 0 :(得分:0)

不要对UIImageView进行类型转换。分配另一个UIImageView对象,设置其图片,然后将UIImageView分配给cell.backgroundViewcell.selectedBackgroundView