Mik*_*ike 5 iphone uibutton uitableview
我有一个表,我有cellForRowAtIndexPath委托,我在该方法中创建了UITableViewCell的实例,我将返回.在cellForRowAtIndexPath的某处,我还将UIButton添加到该单元格的cell.contentView.一切正常,直到我选择带有按钮的单元格.单元格将颜色更改为蓝色(可以),uibutton也将颜色更改为蓝色.现在,如果我点击所选单元格内的UIButton,它就会消失!哇,这很奇怪,我该如何解决?当我点击它时,我希望选定单元格内的UIButton保持不变.
编辑:包含我的cellForRowAtIndexPath实现
- (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;
}
Run Code Online (Sandbox Code Playgroud)
我在OS 4.0 beta上发现了类似的问题,我在UITableViewCell中使用了setImage:forState:UIControlStateNormal.在选择一行并推送另一个表视图后,当我返回到表视图时,该按钮将消失.为了解决这个问题,我在图像上也设置了setImage:forState:UIControlStateHighlighted.我不确定这是否可以解决您的特定问题,但它确实适用于我.我认为在didSelectRowAtIndexPath中设置button.highlighted = NO也可能有效,但我没有尝试过.
| 归档时间: |
|
| 查看次数: |
6803 次 |
| 最近记录: |