开发者

How can you use a uinavigationcontroller at the root of a xib

开发者 https://www.devze.com 2023-03-14 13:52 出处:网络
My app has two routes to go. Login or using the fun parts of the app. The login uses a navcontroller and the fun parts use a tab bar controller.

My app has two routes to go. Login or using the fun parts of the app. The login uses a navcontroller and the fun parts use a tab bar controller.

I would like to de开发者_如何学编程sign my nav controller in IB in a xib and the fun parts in a separate xib file with the tab bar controller. Leaving both controllers out of the MainWindow.xib file.

Does anyone know how to do this? I would like to stay away from programmatically setting up those controllers...


The File's Owner is the LoginController a subclass of NSObject. It has 1 outlet to a UINavigationController

Drop the UINavigationController into the nib file. Connect the navController outlet of the LoginController to the navController you just put in the nib. Drop in a UIView from the pallet, set it to have a navigation bar at the top. Connect the VIEW outlet of the "Root View Controller" of the UINavigationController to the view.

In the App Delegate, you now need to load the nib and file's owner but since it is an NSObject it will have to be loaded differently. First you create the file's owner (LoginController). Then, you load the nib with the file's owner. Finally, you set the windows.rootViewController to the LoginController.navController

_loginViewController = [[LoginViewController alloc] init];
[[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:_loginViewController options:nil];
self.window.rootViewController = _loginViewController.navController;
[self.window makeKeyAndVisible];

Technically, the LoginViewController isn't a subclass of UIViewController but it is still the owner of the nib file. So name it however.

How can you use a uinavigationcontroller at the root of a xib


You should add the UITabBarController to your main XIB and show the login by creating it in code and presenting it with [self.tabBarController presentModalViewController:myLoginController animated:NO]
You might want to do this because maybe you don't want the user to login every time but save the credentials...
presenting modally also gives you the freedom over modalTransitionStyle when animating back to the tab bar controller.

0

精彩评论

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