我的表格视图以非编辑模式显示...
在编辑模式中......
我想在编辑模式下的部门名称字段中显示列表图像。它应该在非编辑模式下隐藏。
我使用tableView: cellForRowAtIndexPath:
..
if (isInEditMode) {
UIImageView *listingImage = [ [UIImageView alloc] initWithFrame:CGRectMake(275, 16, 13, 13)];
listingImage.image = [UIImage imageNamed:@"listing.png"];
[cell.contentView addSubview:listingImage];
[listingImage release];
}
else {
//Need to remove image from cell
}
点击右侧栏按钮(编辑按钮)更新isInEditMode
布尔值。
如何在非编辑模式下删除图像?
先谢谢
答案 0 :(得分:4)
if (isInEditMode) {
UIImageView *listingImage = [ [UIImageView alloc] initWithFrame:CGRectMake(275, 16, 13, 13)];
listingImage.image = [UIImage imageNamed:@"listing.png"];
listingImage.tag = 777;
[cell.contentView addSubview:listingImage];
[listingImage release];
}
else {
[[cell viewWithTag:777] removeFromSuperview];
}
如果[[cell viewWithTag:777] removeFromSuperview];
无效,请尝试使用[[cell.contentView viewWithTag:777] removeFromSuperview];
试试这个,看看是否有帮助
答案 1 :(得分:1)
如果您使用的是自定义UITableViewCell
,则可以将此UIImage
添加为该自定义单元格的属性。当您需要隐藏/删除它时,您可以通过此属性访问它并隐藏/删除它。
e.g。 [cell.listImage setHidden:YES];
答案 2 :(得分:0)
使用[cell.contentView removeSubview:listingImage]
这将要求您在某处保留对listingImage的引用 - 添加一个ivar来存储它。
或者,为每个状态返回不同类型的单元格,一个包含图像,另一个没有。