选定的UIButton在选定的UITableViewCell中消失 [英] Selected UIButton disappears inside selected UITableViewCell

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

问题描述

我有一个表,我有cellForRowAtIndexPath委托给它,我在该方法中创建了UITableViewCell实例,我将返回。在cellForRowAtIndexPath的某处,我还将UIButton添加到该单元格的cell.contentView。一切正常,直到我选择带有按钮的单元格。单元格将颜色更改为蓝色(可以),uibutton也将颜色更改为蓝色。现在,如果我点击所选单元格内的UIButton,它就会消失!哇,这很奇怪,我该如何解决?当我点击它时,我希望UIButton在选定的单元格中保留。

I have a table, I have cellForRowAtIndexPath delegate for it and I have instance of UITableViewCell being created inside that method, which I return. Somewhere in cellForRowAtIndexPath I also add UIButton to cell.contentView of that cell. It all works fine, until I select that cell with button in it. The cell changes color to blue (which is ok), uibutton changes its color to blue too. Now, if I click on that UIButton inside selected cell, it just disappears! Wow, that's weird, how do I fix it? I want UIButton inside selected cell to stay, when I click it.

编辑:包括我的cellForRowAtIndexPath实现

included my cellForRowAtIndexPath implementation

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
static NSString *sectionsTableIdentifier = @" sectionsTableIdentifier ";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: sectionsTableIdentifier];


    for (UIView *view in cell.contentView.subviews)
      [view removeFromSuperview];


     if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
                reuseIdentifier: sectionsTableIdentifier] autorelease];

     }

     CGRect newIconRect = CGRectMake(276, 40, 29, 29);
      UIButton *newIcon = [[UIButton alloc] initWithFrame:newIconRect];
      [newIcon setImage:[UIImage imageNamed:@"mynewicon.png"] forState:UIControlStateNormal];
      [cell.contentView addSubview:newIcon];
      [newIcon release];


    return cell;

    }


推荐答案

我注意到了在OS 4.0 beta上有一个类似的问题,我在UITableViewCell中有一个带有setImage的UIButton:forState:UIControlStateNormal。当我在选择一行并推送另一个表视图后返回到表视图时,该按钮将消失。为了解决这个问题,我在图像上也设置了setImage:forState:UIControlStateHighlighted。我不确定这是否可以解决您的特定问题,但它确实适用于我。我认为在didSelectRowAtIndexPath中设置button.highlighted = NO也可能有效,但我没试过。

I noticed a similar issue on OS 4.0 beta where I had a UIButton in a UITableViewCell with setImage:forState:UIControlStateNormal. The button would disappear when I would return to the table view after selecting a row and pushing another table view. To overcome this, I setImage:forState:UIControlStateHighlighted on the image as well. I'm not sure if this would resolve your particular issue, but it did for me. I think also setting the button.highlighted=NO in didSelectRowAtIndexPath: might have worked as well, but I didn't try it.

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

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