ios - 在 ios 7 中启用编辑时,UITableViewCell subview 不移动

标签 ios objective-c uitableview

我有一个带有 UITableViewCell 自定义类的 TableView ,我已经为每个 UITableViewCell 添加了一些 subview ,现在当我启用这样的编辑时

[tableView_ setEditing:YES animated:YES];

一个红色的删除按钮出现在每个单元格的左侧,每个单元格都向右移动,除了添加到单元格上的 subview 。这会导致按钮出现在 subview 的顶部。如何解决这个问题?谢谢

最佳答案

UITableViewCell 有一个针对其内容的特定 View ,cell.contentView,确保您所有的 addSubview 调用都是针对此 View 而不是单元格。例如:

// good
UILabel* label = [[UILabel alloc] init];
[cell.contentView addSubView:label];

// bad
[cell addSubView:label];

关于ios - 在 ios 7 中启用编辑时,UITableViewCell subview 不移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19839792/

相关文章:

iphone - 如何查看当前 UITableView 行的文档文件大小

objective-c - 将 NSImage 导出到 Excel 工作表

objective-c - 从实例方法调用类方法

ios - Xcode : Some image assets appear Unassigned after git clone

objective-c - SDWebImage 阻塞 tableview 标题标签

objective-c - UIWebView 作为 TableView 部分中页脚的 View 。奇怪的崩溃 - 附上崩溃日志

iphone - 在 xcode 中为不同的构建配置维护不同的 URL

ios - 无法实例化名为 SCNView 的类

ios - 表格单元格中的动画约束更改

ios - swift 错误 : value of optional type 'Double?' not unwrapped