I am using a UIScrollView with an extended content size and have placed many objects within it. It scrolls like a map. Clicking on a button within the UIScrollView will perform a Segue and takes the user to another Scene (another UIView embedded within a UINavigationController). Within the second Scene, clicking on another button will perform another Segue to bring back to the original Scene (the UIScrollView which scrolls like a map).
Everything works fine, EXCEPT that when it returns to the original Scene, it goes back to the default position. HOW do I make it remember the original position? Imagine that it is a map, and by return to it, it should be showing where it left off and users don’t need to re-scroll to the previous place. How can I do that?
I am using Storyboard on iOS 5.
When you perform a segue, that will push the “new” scene on to your navigation stack. If that scene is subsequently “popped” (which would be the default behavior of the UINavigationController’s back button in the new scene), the user should be returned to the original view at the desired content offset automatically. If this is not happening, you may accidentally be pushing a new instance of the original view controller. You should not be performing an additional segue, rather you should be popping the top view controller off of the navigation stack. That said, you can use this rather heavy-handed method for making sure the content offset remains regardless:
Before you perform your segue, set the property to the value of your scrollView’s contentOffset property, e.g.:
When this view controller prepares to make another appearance, set it’s scrollview’s contentOffset: