UITableView使用selectRowAtIndexPath不能默认选中cell的问题
2015-09-30 16:43
1111 查看
http://stackoverflow.com/questions/23025120/selectrowatindexpath-from-another-uiviewcontroller-not-working
按照常理,以及文档说明,函数
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
就是做的这个事,用来人工选中 cell,但是在UITableViewController中确实无效。
但是发现无效。通过上面的帖子,发现是有个UITableViewController 的属性
clearsSelectionOnViewWillAppear
需要设置为NO,这个默认为 YES。导致每次willAppear的时候,会去清理select的数据。
解释如下:
When the table view is about to appear the first time it’s loaded, the table-view controller reloads
the table view’s data. It also clears its selection (with or without animation, depending on the request) every time the table view is displayed. The UITableViewController class implements this in the superclass method viewWillAppear:. You can disable this
behavior by changing the value in the clearsSelectionOnViewWillAppear property.
修改成如下代码就好了:
[cpp] view
plaincopy
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
}
按照常理,以及文档说明,函数
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
就是做的这个事,用来人工选中 cell,但是在UITableViewController中确实无效。
但是发现无效。通过上面的帖子,发现是有个UITableViewController 的属性
clearsSelectionOnViewWillAppear
需要设置为NO,这个默认为 YES。导致每次willAppear的时候,会去清理select的数据。
解释如下:
When the table view is about to appear the first time it’s loaded, the table-view controller reloads
the table view’s data. It also clears its selection (with or without animation, depending on the request) every time the table view is displayed. The UITableViewController class implements this in the superclass method viewWillAppear:. You can disable this
behavior by changing the value in the clearsSelectionOnViewWillAppear property.
修改成如下代码就好了:
[cpp] view
plaincopy
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
}
相关文章推荐
- UICollectionViewController 版本新特性
- 安装VMM 2012 R2累积更新1可能遇到的问题
- IOS开发-CALayer和UIView详细汇总
- c笔记05---逻辑表达式,break,continue 区别
- 《SICP》读书笔记--Chapter 1 Building Abstraction with Procedures
- OC编程无法识别UIImage,undeclared identifier 'image'
- Callable与Futrue创建线程
- 异常处理:使用UTF-8编码Mysql仍然抛出Incorrect string value异常
- UITextField键盘弹出调整承载textField的视图使其不被遮挡
- ueEditor 增加插件,超级方便
- DJANGO基础学习之request对象和response对象
- Android 中数据库查询方法query()中的selectionArgs的用法
- jquey实现的动态表格的新增及删除行
- Android.os.Build
- UITableView 二讲
- android更新UI的方法
- MySQL excel导入错误 Out of range value adjusted for column
- iOS UITableView(表格)
- iOS 滚动视图(UIScrollView) UIPageControl
- vs2010 建立gui 工程后打开console控制台方法