1

I have an app planned out that needs to have a custom menu throughout the application. Its not a toolbar or anything like that so i don't think a regular UINavigationController or a UITabBarController will do the job.

What would be the best approach to creating this custom menu that appears in all views? I thought of just creating a view with the custom menu and alloc it for each view but it seems like a bit of an overkill. Extending UINavigationController might also be an option, but I'm not sure.

Would love to hear your opinions.

Thank you! :)
Shai.

6
  • 2
    I can think of two options: 1. Subclass UINavigationController, hide the standard UINavigationBar's view and create your own view and put it on top of it (ugly and who knows what the results will end up like). 2. Add the menu as a subview of UIWindow so it stays on top of everything throughout the app. Commented Sep 13, 2011 at 15:05
  • Pushing a view over UIWindow might be a great idea, ill look into it. Thanks :) Commented Sep 13, 2011 at 15:19
  • I'll post this as an answer :) Commented Sep 14, 2011 at 7:02
  • @ShaiMishali I need to accomplish the same thing. In my case it is a button throughout the application that will display a menu upon pressing it. What solution did you finally use? And would you do it the same way if you were doing this now? Commented Oct 11, 2012 at 5:06
  • 2
    In all of my apps I always have a UINavigationController as my main UIViewController (appDelegate._window.rootViewController = myNavController) , and I always keep my navController in a singleton, or in my delegate. That way I could push view controllers from anywhere in my app - that would solve your problem. Commented Oct 11, 2012 at 8:57

5 Answers 5

2

The UINavigationController and the UITabBarController are pretty much always the best way to go because they have view and memory management built in. Here's what you can do:

  1. Create a subclass of UITabBarController that hides the tab bar. See the last post on this page: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4091-uitabbarcontroller-hidden-uitabbar.html Make this UITabBarController accessible on a singleton object.
  2. Create a view for your menu and some IBActions corresponding to the menu buttons.
  3. When a menu button is pressed, you can manually switch the tabs of the uitabbarcontroller as follows: tabBarController.selectedIndex = x;
Sign up to request clarification or add additional context in comments.

1 Comment

This sound alike a good idea as well, i just tried just pushing the view over the UIWindow and it also works well for my needs, so i might just stick to that and use a hidden navigationController to actually perform the navigation
1

I agree with ade. I think a popover controller added to a shared class would fit best to the iOS style (I'd put it in AppDelegate in order to have reference to it from anywhere and to avoid creating multiple instances and using only one which you will keep displaying / hiding whenever you wish to see the menu)

3 Comments

How is just different from just adding a custom view as a subview ? I would still have to execute it on each viewDidLoad of a new screen, no ?
nope. Let's say you initialize it in AppDelegate applicationDidFinishLaunching method and keep it retained as a property over your appDelegate class. Whenever you need to show it, from anywhere, you just need to do a call from your class such as [[[UIApplication sharedApplication] delegate].YourPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]. This will use that one unique object(instance) instead of reacreating your view in each ViewDidLoad method in the class you wish to show it.
Futhermore, handling of the popover will prove to be much easier that a custom created view (automatically dismiss when clicking outside of its window, has delegates, etc)
0

I can think of two options: 1. Subclass UINavigationController, hide the standard UINavigationBar's view and create your own view and put it on top of it (ugly and who knows what the results will end up like). 2. Add the menu as a subview of UIWindow so it stays on top of everything throughout the app.

1 Comment

since iOS 5.0, Container View Controllers are probably a much better way to do it. objc.io/issue-1/containment-view-controller.html presents an easy to follow example.
0

I think the best way is to create a custom tool bar and use it across the app. Subclassing UINavBar is another option but not recommended by Apple so I would not go there.

3 Comments

I think it wouldn't work for this specific situation since the location of the custom menu is in one of the bottom corners and with some weird custom shape and not a toolbar-ish shape at all...
you can place this custom bar whereever you want, and play with its shape as much as you want.
So how would this be different than just having a custom UIViewController to be used across the app? same thing more or less, no ?
0

I'd look into using a popover style menu such as WEPopover

1 Comment

Well, I don't think this is what I'm looking for... If it isn't permanent across views, than it doesn't solve my problem. I think i will try @Javier Soto's solution first

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.