ios - UITableViewCell子类化,当选择时消失UIImageView

标签 ios uitableview

我有一个子类 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;

谢谢!

最佳答案

您的自定义 View 看起来只是一个彩色的UIView。当选择 UITableViewcell 时,其中的所有 subview 都会在突出显示时更改其背景颜色。您需要的不仅仅是具有设置背景颜色的 UIView 。您需要一个 UIImageView 或类似的东西。

关于ios - UITableViewCell子类化,当选择时消失UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18524437/

相关文章:

ios - 您可以使用 Xcode 子项目在另一个 iOS 应用程序中运行一个 iOS 应用程序吗?

iphone - 核心位置 didEnterRegion 无效

ios - 以编程方式开始在另一个 TableView 单元格中编辑 UITextField

ios - 从服务器下载图像后动态制作表格 View 单元格高度

swift - 缓存的图像闪烁

ios - Apple 是否推荐使用 "lipo"命令?

ios - 带有附加对象的 NSFetchedResultsController

ios - 火力地堡 REST API

ios - UITableView 不使用 UISearchBar 滚动

iphone - 使用 IB 创建的自定义单元在调用 reloadSections :withRowAnimation: 后隐藏