Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll UITableView to a certain position?

I would like to scroll my UITableView 2 cells down when clicking on a button. The total height for the shift downwards is 100px. How can I accomplish this?

like image 767
Sheehan Alam Avatar asked May 25 '10 15:05

Sheehan Alam


3 Answers

swift 3 version of the answer:

tableView.setContentOffset(CGPoint(x: 0,y :100), animated: false)
like image 128
Ashwin Felix Avatar answered Nov 06 '22 23:11

Ashwin Felix


Set the contentOffset property.

[aTableview setContentOffset:CGPointMake(0,100)];
like image 20
Tom Irving Avatar answered Nov 07 '22 00:11

Tom Irving


If you know what cell you want to scroll to use 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

like image 23
Andiih Avatar answered Nov 07 '22 01:11

Andiih