Reputation: 787
So in my project there is a tableview with each row populated with an image from parse. i was hoping to disable user scroll and have a button scroll down to the next row instead. is this possible?
Figured it out
let button = sender as! UIButton
let view = button.superview!
let cell = view.superview as! <cellname>
let indexPath = tableView.indexPathForCell(cell)
let row = indexPath?.row
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: row!+1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
Upvotes: 0
Views: 1887
Reputation: 1
In Swift 3.0 in Xcode 8:
let mylist = MessageList //your class array
tableView1.scrollToRow(at: IndexPath(row: (mylist?.count)!-1, section: 0), at: UITableViewScrollPosition.bottom, animated: true)
Upvotes: 0
Reputation: 787
I found the solution!
let button = sender as! UIButton
let view = button.superview!
let cell = view.superview as! <cellname>
let indexPath = tableView.indexPathForCell(cell)
let row = indexPath?.row
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: row!+1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
Upvotes: 0
Reputation: 3084
I have made a sample project on git https://github.com/hammyhamza/StackOverflow
Upvotes: 2
Reputation: 2575
You have to use scrollToRowAtIndexPath like so:
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
for indexPath you need to use the NSIndexPath class like so:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowYouDesire inSection:sectionYouDesire];
Upvotes: 0
Reputation: 286
Set the property scrollEnabled to NO.because UITableView is a subclass of UIScrollView. then you can control the scroll use your own code.
Upvotes: 0
Reputation: 1038
Yes, you could use the function scrollToRowAtIndexPath from UITableView to programmatically scroll the table view.
Upvotes: 0