Sunday, 15 September 2013

Preserve Scroll Position When Pushing ViewController In Code in a Storyboard App

Preserve Scroll Position When Pushing ViewController In Code in a
Storyboard App

I have a storyboard app that has a few view controller that need to get
pushed on the navigation stack programmatically, instead of with segues.
I'm using the following code to do it:
POCollectionViewController* vc = [self.storyboard
instantiateViewControllerWithIdentifier:@"categoryView"];
POCategory* destination = (POCategory*)self.collections[indexPath.row];
[vc setShowingCollection:destination];
[self.navigationController pushViewController:vc animated:YES];
My problem is that when I use segues to push view controllers and I press
the 'back' button, the scroll position is preserved, but when I use the
above code and press the 'back' button, my previous view controller
appears with the scroll bar at the top.
Is it re-instantiating a view controller that is supposed to be already on
the navigation stack? How can I preserve the scroll position?

No comments:

Post a Comment