selectRowAtIndexPath不会滚动到UITableView中的正确位置

我有大约80个项目。 如果我select的索引是15(或更less的值),它滚动到正确的位置。 但是,如果select索引是70,它不会滚动。 但是当我手动滚动时它已经select了行。 有没有人有想法如何解决这个问题?

-(void)select:(NSString*)selectedIndex { if(selectedIndex == nil){ return; } UITableView *tableView = (UITableView*)view; if(tableView == nil) { return; } NSIndexPath *nextIndexPath = [self findIndexPath:selectedIndex table:tableView]; if(nextIndexPath != nil && ![viewController isSelectable:[selectedIndex intValue]]){ NSArray *indexPaths = [tableView indexPathsForVisibleRows]; nextIndexPath = [self nextMoveUp:nextIndexPath :indexPaths]; } if(nextIndexPath != nil) { [tableView selectRowAtIndexPath:nextIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; if ([tableView cellForRowAtIndexPath:nextIndexPath] == nil) { // cell is not visible - scroll it into view [tableView scrollToRowAtIndexPath:nextIndexPath atScrollPosition:UITableViewScrollPositionNone animated:YES]; } } } -(NSIndexPath*)findIndexPath:(NSString*)selectedIndex table:(UITableView*)tableView{ NSArray *indexPaths = [tableView indexPathsForVisibleRows]; if(indexPaths == nil || [indexPaths count] == 0) { return nil; } NSIndexPath *lastIndexPath = NULL; for (NSIndexPath *path in indexPaths) { if(path.row == [selectedIndex intValue]){ return path; } lastIndexPath = path; } if(lastIndexPath != nil && lastIndexPath.row < [selectedIndex intValue]){ [tableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; return [self findIndexPath:selectedIndex table:tableView]; } return nil; } 

我刚刚有这个问题。 在我的情况下,我所有的行被定义之前,即在所有行上调用了cellForRowAtIndexPath之前,我正在调用scrollToRowAtIndexPath(或selectRowAtIndexPath)。 我的解决scheme是定义一个方法来select行,并使用performSelectorOnMainThread调用它来延迟,直到第一次刷新完成。