UIPopoverController中UITableViewController 中selectRowAtIndexPath: animated:scrollPosition滚动不到指定的cell的解决方法
按道理 ,下面的代码就可以滚动到指定的 cell并且选中 :
NSIndexPath * index = [NSIndexPath indexPathForRow:selectItemIndex inSection:0];
[self.tableView selectRowAtIndexPath:index animated:NO scrollPosition:(UITableViewScrollPositionTop)];
可是发现,如果是row 比较小,不到底部没啥问题,可以让指定的cell滚动到顶部,可是如果是靠近底部的cell,就不能让指定的cell 显示在可见范围内了。而且如果是用UIViewController来直接弹出 UITableViewController没问题,但是用PopOver 来弹出就不行。
后面发现了一个解决方法:
将这段代码封装成一个函数:
didSelectToProperCell
然后函数里面去调用这段代码
然后调用改成:
[self performSelectorOnMainThread:@selector(didSelectToProperCell) withObject:nil waitUntilDone:NO];
而不是直接去调用,就解决了这个问题。这是一种可用的解决方法。