I have an app that has the following basic layout, please understand I have done a lot of programming, but I am relatively new to IOS and am yet to wrap my head around the Storyboards/segues properly yet.
Effectively, my app has the following screens:
WelcomeViewConroller —ModalSeque–> MenuViewController –modalSegue—> newProjectVC || loadprojectVC —modalSegue–>ProjectScreenVC.
From the project the screen, the user can return to the menuVC screen.
Now, I understand that every segue creates a new instance of a view controller, which is great, I want this to happen, however, when I segue back from my ProjectScreen, and then reenter it again, I get a huge memory leak and very strange behaviour.
I understand that I need to dismiss my View controllers, especially my ProjectScreen when I leave it, however, I can not get this to happen, no matter what I try.
Any help would be greatly appreciated.
In How should I chain viewcontrollers in xcode storyboard? I enumerate a series of ways of going back multiple scenes in a storyboard. But in short, the two easiest options are:
Unwind segues: If only supporting iOS 6 or higher, use unwind segues. So, for example, in your main menu’s view controller, implement a unwind segue:
Also make sure to define that in the main menu’s .h. Then control+drag from the button that you want the segue to the “exit” button in the panel below the scene, and choose the “
gotoMainMenu” option:Navigation controller: If you need iOS 5 support, then just use a navigation controller and replace the modal segues with push segues. Then you can use
popToViewControllerorpopToRootViewControllerAnimatedto jump back multiple scenes. If you don’t want to show the navigation bar, then select the navigation controller in your storyboard, and in the attributes inspector, uncheck “Shows Navigation Bar”:In this scenario, I actually think it’s easiest to make sure your menu scene is the root (and have it do a little detour to the welcome screen, like I discuss in point 4 of that other answer), in which case you can just call
popToRootViewControllerwhenever you want to return to the main menu. But, if the main menu is not the root view controller, and you want to pop back to it, you can either pass a point menu controller from scene to scene, or you can have subsequently presented view controllers do something like the following when they want to get back to the main menu:Elsewhere on Stack Overflow, you’ll see people contemplating ways to nest calls to
dismissViewControllerAnimated, or other variations like that. I personally think that navigation controllers and unwind segues are far easier and more elegant.