【发布时间】:2013-08-30 11:54:52
【问题描述】:
我有一个子类 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;
谢谢!
【问题讨论】:
-
我复制并粘贴了您的代码,但看不到您的身份。当未选择单元格时我看不到图像视图,而当它被选中时我会看到,这正是您应该看到的(如果您将图像视图的背景颜色设为红色,则更容易判断)。
-
嗨@rdelmar 我想在选择和取消选择时查看图像,谢谢
-
什么图片?您是在谈论 selectionColor 吗?里面有图片吗?
-
嗨,是的,我用作选定状态背景的 UIImageView,即使我注释了这个背景颜色,它仍然不显示 uiimageV,谢谢
-
当单元格未被选中时,为什么您希望看到您设置为 selectedBackgroundView 的图像视图?如果您想在选择或取消选择单元格时查看图像视图,只需将其添加为子视图即可。
标签: ios uitableview