11. UITableView & UICollectionView 设置单元格的默认选中状态
1. 场景需求
2. 一个思路
3. UITableView
3.1 通过屏幕点击改变的选中状态回调给代理
//选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
//非选中
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;3.2 代码设置默认选中状态 (要等数据加载完成之后再调用)
//选中
- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
//非选中
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;3.3 补充:代码设置默认选中状态
4. UICollectionView
4.1 通过屏幕点击改变的选中状态回调给代理
4.2 代码设置默认选中状态 (要等数据加载完成之后再调用)
4.3 补充:代码设置选中状态
5. 比较
6. 手动执行代理

Last updated
Was this helpful?