1

I'm trying to loop through several UIViewControllers: where the 1st (start) view is a menu and the final view serves as the results page that loops back to the starting view, after clicking my bar button "Finish".

Testing with the storyboard, I of course use push segue to navigate through the views, but then employ a modal segue with the "Finish" button to bring me back to the starting view controller, which has the embedded navigation controller. This prevents me from using the back button to go past the starting view and undoing past loops. This is a good thing (took me a while to figure out), as I don't want to cycle farther back then the starting view of one loop.

My issue with what I have designed is my memory usage keeps growing, and I do not know how to deallocate/free the views from the previous loops. I plan to use arrays, images, tableViews within this application so I really need some guidance on how to free those large amounts of memory once the "Finish" button is pressed and the application segues to the starting menu view.

I'm using Xcode version 5.1.1. simulating iPhone 3.5-inch.

Thank you

Pholotic
  • 73
  • 7

1 Answers1

0

You say:

... but then employ a modal segue with the "Finish" button

You do not want to to a modal segue with the finish button (because that keeps all the old view controllers in memory and instantiates a new copy of the first scene). If you don't dismiss all of those old view controllers, you'll end up "abandoning" the memory associated with those scenes.

Instead you want to use an unwind segue. This returns to a particular view controller, dismisses any intervening scenes (if any), and releases the memory associated with them and their view controllers.

In your first view controller, create a unwind action:

- (IBAction)unwindToFirstScene:(UIStoryboardSegue *)segue {
    // this is intentionally blank
}

Having created that in the first view controller (the destination of the "finish" button), create a segue between the "finish" button in that last view controller to the exit outlet:

Unwind

When you do that, you'll be prompted for the unwind action.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I am unfamiliar with this type of segue method. I had no idea that the modal segue that solved my last problem is also the culprit causing the current issue. Would you happen to know if I employ this method the same as modal? – Pholotic Jan 08 '15 at 21:57
  • http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them This has a good example of what you suggested! – Pholotic Jan 08 '15 at 22:00
  • @Pholotic This unwind segue works pretty much like a normal segue, but instead of instantiating a new copy of that first view controller, it will instead dismiss the intermediary view controllers (and assuming you don't have other issues, release the memory associated with them) and return you back to the original instance of that first view controller. – Rob Jan 08 '15 at 22:05
  • @Pholotic I notice that you're using Xcode 5, in which case the "exit" outlet might be at the bottom of the scene, such as [shown here](http://stackoverflow.com/a/15512018/1271826). But the idea is the same. – Rob Jan 08 '15 at 22:08