3

I am developing an app where I am using the side moving menu like in the facebook app: Screen Shot of app skeleton

I want to keep that bar up top present through out the app and have the UINavigationControllers get swapped in and out of it for the different sections of the app for Item1 ... ItemN.

How can I go about doing this?

DBD
  • 22,215
  • 12
  • 57
  • 84
Nirma
  • 5,170
  • 4
  • 30
  • 47

3 Answers3

2

Just add it to the window in AppDelegate:

[[[UIApplication sharedApplication] delegate].window addSubview:yourView];

Frankly, you should cast the delegate that comes from sharedApplication

Ondrej Rafaj
  • 4,070
  • 7
  • 38
  • 61
1

I solve this by using a custom container view controller. My rootViewController is just a container view controller which holds my menu and the normal view controller. This allows me to do whatever I want to with the menu, but just slide the menu off the screen and have the child view controller act like it controls everything.

"Implementing a Container View Controller" is a section in the UIViewController Class Reference and holds some good information on how to accomplish the task. There are also a fair number of good videos from Apple at the WWDC when they were introduced in... 2011?

Edit: Added info on custom view controllers.

DBD
  • 22,215
  • 12
  • 57
  • 84
  • This approach goes against the design pattern for UIViewControllers. Most notably, there should only be 1 single UIViewController active at any given time. http://stackoverflow.com/questions/5691226/am-i-abusing-uiviewcontroller-subclassing – averydev Mar 04 '13 at 23:15
  • @AVeryDev - Developer made containment view controllers were introduced as part of iOS 5. Containment controllers themselves have always been an integral part of the design pattern, but before iOS 5, Apple had not given us the API to properly implement our own (we had to use the ones they gave us, tab bar, nav bar, split view, etc). I added more information to my answer pointing to documentation. – DBD Mar 05 '13 at 16:11
  • 1
    Thanks for pointing that out! I somehow hadn't come across that change. In fact I just implemented it in the project I'm working on now. +1! That being said, having multiple UIViewControllers without setting them up specifically as Container View Controllers, complete with parent-child relationships, will always yield lots of hard to debug problems. – averydev Mar 12 '13 at 02:37
  • A much more in-depth link than the one you provided: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html#//apple_ref/doc/uid/TP40007457-CH18-SW6 – Mark Amery Jun 14 '13 at 13:05
0

I solved this issue using child view controllers on the "central" view. I simply made the top most persistant menu a subview that rested on top of the child view controller's view.

Nirma
  • 5,170
  • 4
  • 30
  • 47
  • This approach goes against the design pattern for UIViewControllers. Most notably, there should only be 1 single UIViewController active at any given time. – averydev Mar 04 '13 at 23:14