UITableView
//项目中遇到的
- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition; //可以滚动到指定的 cell并且选中
注意:解决 UIPopoverController中UITableViewController 中selectRowAtIndexPath: animated:scrollPosition滚动不到指定的cell的解决方法
按道理 ,下面的代码就可以滚动到指定的 cell并且选中
NSIndexPath * index = [NSIndexPath indexPathForRow:selectItemIndex inSection:0];
[self.tableView selectRowAtIndexPath:index animated:NO scrollPosition:(UITableViewScrollPositionTop)];
将这段代码封装成一个函数:didSelectToProperCell
然后函数里面去调用这段代码
然后调用改成:[self performSelectorOnMainThread:@selector(didSelectToProperCell) withObject:nil waitUntilDone:NO];
而不是直接去调用,就解决了这个问题。这是一种可用的解决方法
本文介绍了一个UITableView中确保能选中指定cell并滚动到该cell的有效方法。通过将选择操作封装为一个单独的方法,并使用主线程执行此方法,可以解决UIPopoverController环境下无法正确滚动至指定cell的问题。
1万+

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



