0

I've read a lot of questions regarding this issue but still I couldn't find a proper solution to this problem. I have a news application that starts on a Splash Screen (To fetch the news feeds and cache them) then it switches to the main screen which is a mash-up of news articles. You can navigate from this screen to many other screens by clicking on the articles, sections, galleries, videos, etc...I have a fixed header and a footer which I decided to subclass a master UIViewController and place those on that (I'll inherit this UIViewController in my other UIViewControllers)

I've read that the best way to do this is by having multiple view controllers each controlling a specific section of my application. However I'm still a bit confused about how to switch between those properly and responsibly. I tried the storyboard segues but I ran into two problems:

  1. I need to create a lot of segues since you can virtually jump from any screen to any other screen
  2. The segues will not preserve the state of the UIViewController once you jump to another one and once you go back it's reset to it's initial state.

I have also read about the presentModalViewController with which you can push your view as a modal on top of the current controller. However you need to do this a lot and I'm a bit afraid about memory consumption issues.

What's the best way to create a multi-view application without an application view hiearchy (UINavigationController/UITabController/etc...) Typically I'd like to declare all my view controllers at the start and just switch between them as needed (when I first need a view I'll initialize it) Anyone tried something similar before?

Thanks a lot.

EDIT: Thanks for the replies, I went out and watched WwDC session about UIViewController containment and that helped me in understanding how to implement a custom UIViewController container. However there's still something I can't grasp.

When I create a custom UIViewController container I need to add children to it using addChildViewController, and that will fire the willMoveToParentController event on my child UIViewController.

Then I add the child controllers subviews into the container views using [self.view addSubview...] however this only load the views and doesn't link them to the events I have created inside my child UIViewController.

Should I use something else than addSubview? or should I use a separate UIView class to wire my events in?

1 Answers1

0

If you use the new iOS 5 I suggest you to read about Implementing a Container View Controller section in UIViewController Class Reference.

In this manner you can create a sort of container controller that manages your other view controllers. The key aspect is that you can implement your own controller and switching animations.

This pattern can be applied both to storyboard and non-storyboard application. I prefer the second approach.

About memory consumption, you have not to worry if you have managed content in the right way. Maybe, if you have already cached the data, you can add or remove the current displayed controller's view from the view hiearchy (but leaving the controller as a child of your master controller) or remove both.

Hope it helps.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
  • I've created a custom UIViewController container after watching the WWDC 2011 sessions about view containment and hierarchy. Thanks a lot. – ravenstone Mar 04 '12 at 19:17