我有一个表,我有它的 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:forState:UIControlStateNormal 有一个 UIButton.当我在选择一行并按下另一个表视图后返回表视图时,该按钮将消失.为了克服这个问题,我也在图像上设置了图像: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 内消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!