选择时从 UITableViewCell 消失的视图 [英] Views disappearing from UITableViewCell when selected

查看:25
本文介绍了选择时从 UITableViewCell 消失的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义 UITableViewCells 的 UITableView.单元格的内容保存在扩展 UIView 的单独类中(我有 3 种内容,我通过隐藏和显示视图进行切换,我采用这种方法是因为我想在单元格之间进行转换).所以让我们假设我有一个可见的视图并添加到单元格的 contentView 中.这个视图包含一些文本和一些由 UIViews 组成的矩形.到目前为止一切都很好,但奇怪的是当我触摸单元格时,矩形消失了,文本保持不变.你知道可能是什么问题吗?我也尝试将视图添加到 backgroundView,它也是这样做的.

I have a UITableView with custom UITableViewCells. The content of the cell is kept in a separate class extending UIView (i have 3 kind of contents which i switch by hiding and showing views, i took this approach because of the way i wanted to make the transition between cells). So let's assume i have one of the views visible and added to the contentView of the cell. This view contains some text and some rectangles made of UIViews. Everything good till now, but the weird thing is when i touch the cell, the rectangles simply disappears, the text stays the same. Do you know what might be the problem? I tried to add the view to the backgroundView as well, it's doing the same.

- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {
    self.active = NO;
    state = -1;

    // Touch is not working if the view has no bounds
    self.backgroundView = [[UIView alloc] init];
    self.backgroundColor = [UIColor clearColor];
    self.selectedBackgroundView = [[UIView alloc] init];
    self.selectedBackgroundView.backgroundColor = [UIColor clearColor];
    self.clipsToBounds = YES;
    self.contentView.clipsToBounds = YES;

    // Add empty view
    emptyView = [[View1 alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) andRadius:CELL_DOT_RADIUS];
    emptyView.userInteractionEnabled = NO;
    [self.backgroundView addSubview:emptyView];

视图:

- (id) initWithFrame:(CGRect)frame andRadius:(int)r {
self = [super initWithFrame:frame]; radius = r;

if (self) {

    int outerlineWeight = 1;

    timelineView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width/4, frame.size.height/2, 1, 1)];
    [self addSubview:timelineView];


    dotView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width/4-radius, frame.size.height/2-radius, radius*2, radius*2)];
    dotView.layer.cornerRadius = radius;
    dotView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    [self addSubview:dotView];

    UIView *n = [[UIView alloc] initWithFrame:CGRectMake(160, 0, 50, 20)];
    n.backgroundColor = [UIColor redColor];
    [self addSubview:n];


    middleText = [[UILabel alloc] initWithFrame:dotView.frame];
    middleText.font = [UIFont systemFontOfSize:12];
    middleText.textColor = [UIColor grayColor];
    middleText.backgroundColor = [UIColor clearColor];
    middleText.textAlignment = NSTextAlignmentCenter;
    [self addSubview:middleText];

这是来源,因此您可以根据需要自行尝试.如您所见,橙色矩形消失了,但文本没有.对于我需要做的什么都不应该消失,在最好的情况下,我想改变它们的颜色.http://ge.tt/6wRBObD1/v/0?c

This are the sources so you can try for yourself if you want. As you can see the orange rectangle disappears but the text not. For what i need to do nothing should disappear, in the best case i want to change their colours. http://ge.tt/6wRBObD1/v/0?c

推荐答案

在 swift 中,您需要全局声明 viewcontroller 对象,这将导致 Strong,以防如果您在本地声明它会导致单元格不断消失.

In swift you need to declare viewcontroller object globally that would result in Strong, in case if you declare locally it results in keep disappearing the cells.

var refineViewController : RefineViewController?

然后您可以使用以下不会导致单元格消失的代码访问该控制器.

then you can access that controller using below code that would not result in disappearing cells.

func showRefineView(isFindHomeTab isFindHomeTab : Bool){


    refineViewController =   RefineViewController(nibName: String(BaseGroupedTableVC),bundle : nil)

    refineViewController!.refineSearchDelegate = self

    refineViewController!.view.frame = CGRectMake(0, -490, self.view.frame.size.width, self.view.frame.size.height)

    UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveEaseOut, animations:
        {

            self.refineViewController!.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
            self.refineViewController!.isFindHomeTab = isFindHomeTab

        }, completion: nil)

        self.view.addSubview(refineViewController!.view)

}

这篇关于选择时从 UITableViewCell 消失的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆