can*_*boy 11 iphone cocoa-touch scroll objective-c uitableview
带有表格的视图会被推到屏幕上,我希望它在屏幕实际显示之前滚动到表格中的某一行.我在最终的viewcontroller中使用这段代码.
NSIndexPath *scrollToPath = [NSIndexPath indexPathForRow:5 inSection:0];
[theTable scrollToRowAtIndexPath:scrollToPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
Run Code Online (Sandbox Code Playgroud)
当我把它放在viewDiDAppear方法中时,它会从表格的初始位置(在顶部)短暂闪烁到我想要的行.我不希望它显示初始位置.如果我将它放在viewDidLoad或viewWillAppear中,那么它会因NSRangeException崩溃,可能是因为该表尚未设置.
如何在不显示初始位置的情况下滚动它?
can*_*boy 15
感谢Shaggy和垂死的仙人掌指向我正确的方向.答案是加载表并在viewWillAppear中滚动:
-(void)viewWillAppear:(BOOL)animated
{
[theTable reloadData];
NSIndexPath *scrollToPath = [NSIndexPath indexPathForRow:5 inSection:0];
[theTable scrollToRowAtIndexPath:scrollToPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7735 次 |
最近记录: |