Usama bin Attique
Usama bin Attique

Reputation: 337

Maintain the table view's scroll position

In my app I have a list of foods, that pop up from the side menu like this

enter image description here

Upon clicking any index it segues to a food screen where it shows respective details. this ham icon launches the side menu. what I want is when the user lets say selects the 28th or 30th index down the list. when he clicks again on the hamIcon he should come back to the same scroll position where he left, currently, it takes the user back to the top, how can I achieve that. I browsed stack and all I could find was obj-c version of the problem. and I don't know obj-c at all. I also came across a third party library but I don't want to do that for such a trivial task. Please guide me in the right direction.

Upvotes: 1

Views: 571

Answers (1)

Waseem
Waseem

Reputation: 130

You can simply store the last click index path in didSelectRowAtIndexPath.

And simply call scrollToRowAtIndexPath method from viewWillApperar.

        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

Hope this help you!

Upvotes: 3

Related Questions