iOS

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];

而不是直接去调用,就解决了这个问题。这是一种可用的解决方法

原文地址:https://www.cnblogs.com/junhuawang/p/5458413.html