Ios UITableViewCell子类,选中时将消失UIImageView
我有一个子类UITableViewCell,工作正常,选中时,它有一个自定义单元格颜色和文本颜色,并保持选中状态,直到选中其他单元格 问题是,我在这个单元格中有一个UIImageView,当未选中该单元格时,它会显示出来,但如果选中该单元格,UIImageView就会消失 这是我的密码Ios UITableViewCell子类,选中时将消失UIImageView,ios,uitableview,Ios,Uitableview,我有一个子类UITableViewCell,工作正常,选中时,它有一个自定义单元格颜色和文本颜色,并保持选中状态,直到选中其他单元格 问题是,我在这个单元格中有一个UIImageView,当未选中该单元格时,它会显示出来,但如果选中该单元格,UIImageView就会消失 这是我的密码 #import "MMSideDrawerTableViewCell.h" @implementation MMSideDrawerTableViewCell - (id)initWithStyle:(UIT
#import "MMSideDrawerTableViewCell.h"
@implementation MMSideDrawerTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIView * backgroundView = [[UIView alloc] initWithFrame:self.bounds];
[backgroundView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[backgroundView setBackgroundColor:[UIColor colorWithRed:77.0/255.0
green:79.0/255.0
blue:80.0/255.0
alpha:1.0]];
[self setBackgroundView:backgroundView];
UIView *sa = [[UIView alloc]initWithFrame:CGRectMake(180, 4, 20, 20)];
sa.backgroundColor = [UIColor greenColor];
[self.contentView addSubview:sa];
[self.textLabel setTextColor:[UIColor
colorWithRed:230.0/255.0
green:236.0/255.0
blue:242.0/255.0
alpha:1.0]];
[self.textLabel setShadowColor:[[UIColor blackColor] colorWithAlphaComponent:.5]];
[self.textLabel setShadowOffset:CGSizeMake(0, 1)];
[self.textLabel setFont:[UIFont boldSystemFontOfSize:16.0]];
//highlited
UIImageView *selectionColor = [[UIImageView alloc] init];
selectionColor.backgroundColor = [UIColor blackColor];
self.selectedBackgroundView = selectionColor;
self.textLabel.highlightedTextColor = [UIColor colorWithRed:49/255.0f green:101/255.0f blue:135/255.0f alpha:1];
}
return self;
}
@end
有什么问题?
如何使用选定的单元格显示我的图像
编辑,
如果我为背景选定状态的行添加注释,它仍然隐藏图标uiImageView
//self.selectedBackgroundView = selectionColor;
谢谢 您的自定义视图看起来只是一个彩色的
UIView
。选择UITableViewcell
时,其内部的所有子视图都会在高亮显示时更改其背景色。您需要的不仅仅是带有设置背景色的UIView
。你需要一个UIImageView
,或者类似的东西。我复制并粘贴了你的代码,但我看不到你是什么。当单元格未被选中时,我看不到图像视图,而当它被选中时,我会看到,这正是您应该看到的(如果将图像视图的背景颜色设置为红色,则更容易判断)。您好@rdelmar我想在选中和取消选中时看到图像,谢谢什么图像?你是说selectionColor吗?您有图像吗?您好,是的,我使用UIImageView作为选定状态的背景,即使我使用此背景色,它仍然不会显示uiimageV,谢谢您为什么希望在未选择单元格时看到您设置为selectedBackgroundView的图像视图?如果您想在选中或取消选中单元格时查看图像视图,只需将其作为子视图添加即可。您好,谢谢,我也尝试了此操作,我已对选定状态的背景进行了注释,但存在相同的问题,我已编辑了我的问题。您是否尝试使用纯色图像作为自定义视图背景,而不仅仅是颜色?或者甚至使用类似的东西?self.customView.backgroundColor=[UIColor WithPatternImage:[UIImage ImageName:@“green.png”];我尝试了你的第二个建议,但不起作用,但在图像视图中使用纯色图像确实有效+1很高兴知道另一个选项也不起作用。很奇怪的行为。不过,我很高兴图像选项起作用了。关于单元格子视图在选择时更改背景颜色的信息,您有参考资料吗?我哪儿都没见过。