试图弄清楚如何为tableViewCell
设置所选图像。
旧的写作方式是cell.selectedImage
,但自3.0以来已弃用。
我尝试了很多东西,但是不能把它弄得太干净了。
谢谢! 约什
答案 0 :(得分:24)
根据Deprecated UITableViewCell Methods文档,您应该使用imageView的highlightedImage属性作为selectedImage的替代。例如:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.imageView.image = [UIImage imageNamed:@"deselected_image.png"];
cell.imageView.highlightedImage = [UIImage imageNamed:@"selected_image.png"];
答案 1 :(得分:9)
您可以设置如下所示的选定背景....
UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage.png"]];
cell.selectedBackgroundView = selBGView;
答案 2 :(得分:4)
这不起作用,因为你可能像这样设置正常的状态图像
cell.imageView.image = ///
尝试一下 - 它对我很有用!!
UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage_selected.png"]];
cell.selectedBackgroundView = selBGView;
[selBGView release];
UIImageView *BGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage.png"]];
cell.backgroundView = BGView;
[BGView release];
答案 3 :(得分:2)
试试这个......
UIImage *bgImage = [UIImage imageNamed:@"icon_call.png"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
[bgImageView setFrame:CGRectMake(280, 2, 30, 38)];
//Finally give this imageView to the cell
[cell.contentView addSubview:bgImageView];
希望它能解决你的问题!
答案 4 :(得分:1)
使用这个!:
selectionBackground = [UIImage imageNamed:@"background.png"];
cell.selectedBackgroundView =[[UIImageView alloc] init];
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;