如何使特定的UITableViewCell在UITableView中有更多的行时在屏幕上可见

我在表格视图中有20行,我devise(或说resize)的UITableView在屏幕的一半(使用IB)和半屏幕我显示与特定的UITableViewCell相关的东西。 将在半屏幕中显示哪个单元的细节是决定的运行时间。 我想要加载视图倒数第二个单元格时可见的单元格。

我怎样才能做到这一点?

UITableView类提供:

 -(void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated; 

这似乎是你在找什么。

NSIndexPath对象可以使用:

 +(NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section; 

我发现确保整个单元格可见的最简单的方法是要求tableview确保单元格的矩形是可见的:

 [tableView scrollRectToVisible:[tableView rectForRowAtIndexPath:indexPath] animated:YES]; 

一个简单的方法来testing它只是把它放到-(void)tableView:didSelectRowAtIndexPath: – 点击任何单元格,然后将其滚动到位,如果它部分隐藏。

尝试scrollToRowAtIndexPath:atScrollPosition:animated ::

 NSUInteger indexArray[] = {1,15}; NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:indexArr length:2]; [yourTableView scrollToRowAtIndexPath:indexPath atScrollPosition: UITableViewScrollPositionTop animated:YES];