实现方式
-
如果要有默认选择在初始化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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。