iOS UI 的坑:不要 remove UITableViewCell 的 contentView
来源:互联网 发布:python与自然语言处理 编辑:程序博客网 时间:2024/06/05 02:46
问题背景
看到标题,你可能会想,怎会有人傻到这么做?好吧,一个像我一样没有经验的程序员的确可能。
这个问题的背景是,在需要重绘UITableViewCell
时,经常遇到需要清空所有subview的情况。而我们有这样一段代码可以利用:
UIView+Utils.m
- (void)removeAllSubviews { for (UIView *subView in self.subviews) { [subView removeFromSuperview]; }}
正确的做法
正确的做法是,把所有的子 view 都加在 contentView
上。
SomeTableViewCell.m
[self.contentView removeAllSubviews];// ……[self.contentView addSubview:view];
错误的做法
错误的做法是,把子 view 加在 cell 本身的 view 上。
SomeTableViewCell.m
[self removeAllSubviews];// ……[self addSubview:view];
这样在removeAllSubviews
时,不仅 remove 掉了自己添加的那些子 view,也一同 remove 掉了UITableViewCell
的contentView
。
错误的后果
错误的做法造成的后果是:在 iOS 7(测试用版本为7.1)上,cell 显示为一片空白。所有的 subview 都显示不出来。在 iOS 6 和 iOS 8 上均正常。
总结
- 千万不要 remove
UITableViewCell
的contentView
- 一定要测试到每个系统版本。在 iOS 6 和 iOS 8 都正常,仅在 iOS 7 上出现的 bug,是真的存在的。
0 0
- iOS UI 的坑:不要 remove UITableViewCell 的 contentView
- iOS UI 的坑:不要 remove UITableViewCell 的 contentView
- UITableViewCell的contentView
- Cell简介和UITableViewCell的contentView
- 关于(UITableViewcell)contentView高度的问题
- iOS UICollectionViewCell 的 contentView 注意事项
- UITableViewCell的contentView中的UITextField的值获取的方法
- UITableViewCell使用cell和cell.contentView的区别
- UITableViewCell中的使用cell和cell.contentView的区别
- iOS cell与cell.contentView的区别
- UI基础-iOS黑马-UITableViewCell的常见属性3-LoLdemo
- iOS开发UI篇—UITableviewcell的性能问题
- iOS开发UI篇—UITableviewcell的性能问题
- iOS笔记UI--修改系统UITableViewCell的ImageView大小
- iOS开发-UI控件:UITableViewCell划动删除的实现
- UITableViewCell选中时contentView中各组件的高亮状态
- IOS UITableViewCell的使用
- iOS UITableviewCell的删除
- 墓地雕像
- 好记性不如烂笔头25-JAVA处理数据库事务(3) - 事务回滚点
- LINK_LIBRARIES: Targets may link only to libraries. CMake is dropping the item.
- 四种生成和解析XML文档的方法详解(介绍+优缺点比较+示例)
- bzoj 1047 题解
- iOS UI 的坑:不要 remove UITableViewCell 的 contentView
- guice入门学习与实例一
- Java中 Timer缺陷,用ScheduledExecutorService替代
- virtualbox虚拟机安装Mac OS 10.6.x全过程
- set_new_handler
- [Swift 开发] swift支持多线程操作数据库类库-CoreDataManager
- 读 C 标准库 memcpy 函数 源码 感悟
- linux yum命令详解
- Offcie2013 无法显示 Aurora解决方法