Ale*_*exR 8 cocoa-touch objective-c uitableview ios
我经常需要将表视图单元格设置为初始选择状态,我使用以下代码:
[self.tableView selectRowAtIndexPath:indexPath
animated:NO scrollPosition:UITableViewScrollPositionNone];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:YES];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
Run Code Online (Sandbox Code Playgroud)
我正在使用selectRowAtIndexPath:indexPath并且setSelected:YES同时,因为我不完全理解这两种方式中的哪一种是以编程方式选择单元格的首选方式.
我应该使用哪一个陈述?为什么?
我相信你想要使用的方法是selectRowAtIndexPath:animated:scrollPosition:.通常,您应该将单元状态管理保留在表视图中.在选择的情况下,它存储并维护一组选定的索引路径,因此在为其重用不同的单元后,将保持选择正确的行.也没有必要调用这两种方法,它只是多余的.
| 归档时间: |
|
| 查看次数: |
9960 次 |
| 最近记录: |