1

I would like keep viewController's in memory and show them later in custom order by example call vc3 and after vc6 without init them again, they must stay in the same state. I had thinked to use navigationController , but I does not want navigation bar and I'm not sur that I can call viewcontroller in custom order. I have tried to put viewController in global array, but when i call them I have an error : 'Application tried to present modally an active controller'. What do you think about this , how can I handle my viewControllers and show them without initialize them again. I'm listening all way.

I had read that in IOS we must recycle the view, so I have a question. What is the best way to handle recycle view. If I want serve to my user the same view without init the viewcontroller responsable to this view. how i must do that , what is the best structural choice to adopt .. Have a big viewcontroller and handle view with addsubview removesubview ... or many viewcontroller for each view type , and here i don't know how to recycle and keep trace of my viewcontroller (i don't want use navigation controller ) .

user2718075
  • 333
  • 2
  • 4
  • 15

1 Answers1

0

First of all you can hide navigation bar in navigation controller:

  • self.navigationBarHidden = true (For UINavigationController)

  • self.navigationController?.navigationBarHidden = false (for UIViewController inside UINavigationController)

Also it's okey in your situation to store in global array (but it's better to have helper class for this), so while your UIViewControllers will be in memory - you can reuse them.

You problem relates to the navigation (good answer is here - https://stackoverflow.com/a/7534019/1830598). So you have to manage this order with dismissing and presenting UINavigationController again or find another solution.

Example of your usecase:

  1. Present UINavigationController with any ViewController
  2. Store any view controller as storedViewController
  3. At rootViewController of UINavigationController (that is presented) add code: self.navigationController?.viewControllers = [storedViewController, self]
  4. Now you will be at second view controller at UINavigationController and by pressing back you will get to your storedViewController
Community
  • 1
  • 1
Alexander Zimin
  • 1,700
  • 1
  • 15
  • 19
  • thank , in navigationController, can I call viewcontroller in custom order ? I have read the post you suggested but not find a way to help. When I use presentViewController for VC3 , what is it about VC2 , was it killed ? or it is staying in memory. you talked me about helper class, do you think about navigationController class ? – user2718075 Jun 02 '16 at 15:47
  • @user2718075 you could set order of view controllers in navigation controller in code with it's property, so something like `navigationController?.viewControllers = [VC2, VC1]` – Alexander Zimin Jun 02 '16 at 15:55
  • @user2718075 added example of sample usecase – Alexander Zimin Jun 02 '16 at 16:01
  • the application come with a lot of code at this time. I think set a navigationController will disturb a lot , now the navigation is ok. , i need a simple way(if exist) to show the user all opened viewcontrollers and let him chose one. In my application some viewcontroler open file like video, pdf etc ... the user consult a document and with the menu, show all viewcontroller that are open, he can click on and show it at the same state that he was left. – user2718075 Jun 02 '16 at 16:21