我有一个子类 UITableViewCell,工作正常,选择后,它具有自定义单元格颜色和文本颜色,并保持选中状态,直到选择其他单元格。
问题是,我在这个单元格中有一个 UIImageView,当未选择单元格时它会显示,但是如果选择了单元格,则 UIImageView 会消失,
这是我的代码,
#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;
谢谢!