业务要求外部事件能动态设置选中indexPath的cell,最初想法:
UITableViewCell *cell = [selftableView:_chapterTableView cellForRowAtIndexPath:indexPath];
cell.selected =YES;
[_chapterTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[_chapterTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
结果没有效果,之后才发现tableView有这个方法:
[_chapterTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
同时,取消之前选中的cell:
[_chapterTableView deselectRowAtIndexPath:oldPath animated:NO];
问题解决