实现方式
-
如果要有默认选择在初始化tableView完成后写
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; -
然后在cell中实现
- (void)setSelected:(BOOL)selected animated:(BOOL)animated方法- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if (selected) { self.selBtn.selected = YES; }else { self.selBtn.selected = NO; } } -
在
didSelectRowAtIndexPath方法中给点击的cell手动选中,并不需要刷新表格[tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
至此结束,可以看一下效果
作者:Pnyg_回眸
链接:https://www.jianshu.com/p/d067d82dbbc9
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

本文详细介绍如何在UITableView中设置默认选中的单元格,包括在初始化TableView后进行设置的方法,以及在cell中实现setSelected方法来响应选择状态的改变。同时,文章还介绍了如何在didSelectRowAtIndexPath方法中手动选中单元格,而无需刷新整个表格。
2万+

被折叠的 条评论
为什么被折叠?



