视图显示前立即滚动到表中的行 [英] Scroll immediately to row in table before view shows

查看:85
本文介绍了视图显示前立即滚动到表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有表格的视图被推送到屏幕上,我希望它在屏幕实际显示之前滚动到表格中的某一行。我在最终的视图控制器中使用这个代码。

A view with a table gets pushed onto the screen and I want it to scroll to a certain row in the table before the screen actually displays. I use this code within the final viewcontroller.

NSIndexPath *scrollToPath = [NSIndexPath indexPathForRow:5 inSection:0]; 
[theTable scrollToRowAtIndexPath:scrollToPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

当我把它放在viewDiDAppear方法中时,它从表的初始位置顶部)到我想要的行。我不想让它显示初始位置。如果我把它放在viewDidLoad或viewWillAppear然后它崩溃与一个NSRangeException,可能是因为该表尚未设置。

When I put it in viewDiDAppear method, then it briefly flashes from the intial position of the table (at the top) to the row I want. I don't want it to show the initial position. If I put it in viewDidLoad or viewWillAppear then it crashes with a NSRangeException, presumably because the table isn't set up yet.

如何让它滚动而不显示初始位置?

How would I get it to scroll without showing the initial position?

推荐答案

感谢Shaggy和Dying仙人掌指向我的方向。答案是加载表并滚动到viewWillAppear:

Thanks to Shaggy and Dying Cactus for pointing me in the right direction. The answer is to load the table and scroll in viewWillAppear:

-(void)viewWillAppear:(BOOL)animated
{
    [theTable reloadData];
    NSIndexPath *scrollToPath = [NSIndexPath indexPathForRow:5 inSection:0]; 
    [theTable scrollToRowAtIndexPath:scrollToPath atScrollPosition:UITableViewScrollPositionTop animated:NO];   
}

这篇关于视图显示前立即滚动到表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆