UITableView - 滚动到顶部 [英] UITableView - scroll to the top
本文介绍了UITableView - 滚动到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表视图中,我必须滚动到顶部。但我不能保证第一个对象将是第0部分,第0行。可能是我的表视图将从第5节开始。
In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section number 5.
所以我得到了一个异常,当我打电话:
So I get an exception, when I call:
[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
还有另一种滚动到表格视图顶部的方法吗?
Is there another way to scroll to the top of table view?
推荐答案
UITableView是UIScrollView的子类,因此您也可以使用:
UITableView is a subclass of UIScrollView, so you can also use:
[mainTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
或
[mainTableView setContentOffset:CGPointZero animated:YES];
在Swift中:
mainTableView.setContentOffset(CGPointZero, animated:true)
在Swift 3中&安培;上面:
And in Swift 3 & above:
mainTableView.setContentOffset(.zero, animated: true)
这篇关于UITableView - 滚动到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文