views:

265

answers:

1

I'm working on an iPhone app where I'm using a navigation controller (UINavigationController) to navigate through the various child views, and I would like to add a uiview to either the main window or the navigation controller, as a footer overlay that shows up on top of all the child views. I've tried this through interface builder, and programmatically, but nothing seems to work.

Working in interface builder, I've tried adding the footer to the bottom of the main window, and decreasing the height of the child views so the footer would show up, but the children seem to resize to fill the whole window. I've tried playing with some of the options, like 'wants full screen', 'resize view from NIB', tried to resize the navigation controller and couldn't. Same problem when I try to add it programmatically instead.

I can add a toolbar to the navigation controller in interface builder, is there a way to add a UIView instead? Or even attach a UIView to a toolbar? I'm sure there's a simple way to do what I'm trying, I'm hoping someone out there has had a similar experience.

Thanks!

+1  A: 

If you want to have a toolbar sized custom view you can just position it where the toolbar would be and add it to the window as a subview above your navigation controller. Then you don't have to worry about autoresizing ruining your fun, you'll just always be drawing your view over the navController's toolbar.

[myWindow insertSubview:newView aboveSubview:myNavController.view]

Just make sure you adjust the size of your view if you want to respond to device rotations, as the toolbar size changes then.

You may also have success creating a view hierarchy that looks like this:

UIWindow
  Subview 1: Custom view which holds app content
    Subview 1a: UINavigationController with your main view as its root view
  Subview 2: Custom view which holds your footer content
    Subview 2a...2z: whatever views you need inside your footer

That way you can make your footer whatever height you want. Just set the appropriate autoresizingMask properties on your window's two subviews so that you can ensure proper positioning as well as respond to interface orientation changes automatically.

Victorb