[英]How to scroll UITableView to a certain position?
I would like to scroll my UITableView 2 cells down when clicking on a button. 我想在点击按钮时滚动我的UITableView 2单元格。 The total height for the shift downwards is 100px. 向下移动的总高度为100px。 How can I accomplish this? 我怎么能做到这一点?
设置contentOffset
属性。
[aTableview setContentOffset:CGPointMake(0,100)];
If you know what cell you want to scroll to use scrollToRowAtIndexPath:atScrollPosition:animated: 如果您知道要滚动的单元格,请使用scrollToRowAtIndexPath:atScrollPosition:animated:
http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated : http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated :
otherwise use the contentOffset property or scroll by pixels http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/doc/uid/TP40006922-CH3-SW26 否则使用contentOffset属性或按像素滚动http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/doc/uid/TP40006922-CH3-SW26
swift 3版的答案:
tableView.setContentOffset(CGPoint(x: 0,y :100), animated: false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.