views:

208

answers:

1

I have a view (and corresponding view controller) in my iPhone app that allows the user to edit settings for the application. This view is accessible via a menu (a table view). I use pushViewController in my UIViewController subclass to get it shown. When I do this, it appears as I expect - the nav bar appears on top of the xib, and the empty space I left up there in the xib is occupied.

I also sometimes show that settings view as a modal view using presentModalViewController. When I do this, the top of the xib starts at the bottom of the nav bar instead of underneath it.

The documentation does say that presentModalViewController will resize the view to fit, so I could see this being expected behavior. However, for me, it isn't desired behavior.

I can kind of work around it by setting the settings view controller to not show the nav bar, but then there's a weird empty space at the top of the view.

Ideally, I'd like to use the same xib in both of these situations. However, maybe that's not a best practice? How do you guys usually reuse a xib?

I was thinking that maybe I could have the view controller shift all of the controllers up if it's in modal mode, but I'd like something better, if it's available.

+1  A: 

Each UIView has an autoresizingMask property. By configuring that (can be done in Interface Builder), you should be able to reuse the view and have it automatically resize to take up the whole screen when the nav bar should not be there.

Apple's documentation is here:

http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple%5Fref/doc/uid/TP40007072-CH8-SW10

Kobski
Well, in this case, the nav bar appears in both situations - when loaded from a view controller stack and when show as a modal view. In the second case, it automatically moves the controls down to account for the nav bar, whether or not the autoresizing mask has a "strut" at the top.It is good to know about layoutSubviews, however.
Jim