[英]How can you use a uinavigationcontroller at the root of a xib
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.
登录使用navcontroller,有趣的部分使用标签栏控制器。
I would like to design my nav controller in IB in a xib and the fun parts in a separate xib file with the tab bar controller. 我想用标签栏控制器在ibb中的IB中设计我的导航控制器,并在单独的xib文件中设计有趣的部分。 Leaving both controllers out of the MainWindow.xib file.
将两个控制器都保留在MainWindow.xib文件之外。
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. 文件的所有者是LoginController,它是NSObject的子类。 It has 1 outlet to a UINavigationController
它有1个到UINavigationController的出口
Drop the UINavigationController into the nib file. 将UINavigationController放到nib文件中。 Connect the navController outlet of the LoginController to the navController you just put in the nib.
将LoginController的navController出口连接到刚放在笔尖中的navController上。 Drop in a UIView from the pallet, set it to have a navigation bar at the top.
从托盘中放入UIView,将其设置为在顶部具有导航栏。 Connect the VIEW outlet of the "Root View Controller" of the UINavigationController to the view.
将UINavigationController的“ Root View Controller”的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. 在应用程序委托中,您现在需要加载笔尖和文件的所有者,但是由于它是一个NSObject,因此必须以不同的方式加载。 First you create the file's owner (LoginController).
首先,您创建文件的所有者(LoginController)。 Then, you load the nib with the file's owner.
然后,用文件的所有者加载笔尖。 Finally, you set the windows.rootViewController to the LoginController.navController
最后,将windows.rootViewController设置为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. 从技术上讲,LoginViewController不是UIViewController的子类,但它仍然是nib文件的所有者。 So name it however.
因此命名。
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]
您应该将UITabBarController添加到您的主XIB中,并通过在代码中创建登录名并使用
[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. 动画显示回到选项卡栏控制器时,模态呈现还使您可以自由地使用modalTransitionStyle。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.