开发者

Iphone UIViewController to UINavigation controller programmatically

I have been stuck on this for a few days now and it is killing me... In my viewDidLoad event, I am trying to programmatically add a full screen UINavigationController to a subview of my view controller. So far, I have only succeeded in doing two things...

1) Only a grey screen shows up

OR

2) I get something that resembles a navigation controller added to the view controller, instead of being my navigation controller from a XIB it is just a generic one... even though I loaded from the XIB. Oddly enough it is always shifted 25 pixels downward and slightly cut off.

I have read every single link on google and I can't seem to figure this out. I just created a new viewcontroller... added a UINavigationController to it... try to load that view controller and it messes up.

Any h开发者_开发知识库elp is greatly appreciated!!!!


Instead of having the UINavigationController be a child of some other view controller, make the UINavigationController the root controller itself. The navigation controller is one of the special "container" view controllers, and it generally wants to own the whole screen and be at the root of the controller hierarchy (except in certain circumstances).

Try something like this:

UINavigationController * rootNavController = [[UINavigationController alloc] initWithRootViewController:myRootControllerInTheNavController];
[window addSubview:[rootNavController view]];

Which will obscure any existing views with the nav controller (those existing things will still be there when you -removeFromSuperview the nav controller's view). The nuclear option is to set your UIWindow's rootViewController property with the nav controller, but it sounds from your comment that this may not be what you want to do here.

Possibly a cleaner approach: If it accomplishes what you want, I believe you could also take your nav controller and present it modally (see docs for uiviewcontroller) from whatever the current view controller is. Set the transition appropriately, and while you're in the nav stack, the nav controller will be visible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜