简体   繁体   English

如何在xib的根部使用uinavigationcontroller

[英]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.

相关问题 我如何在没有xib的情况下使用UINavigationController? - How do I use the UINavigationController without a xib? 如何在Xcode(xib)中使用后退按钮创建“ UINavigationController”? - How to create “UINavigationController” with backbutton in Xcode (xib)? 您可以使用为带有故事板的xib创建的视图控制器吗? - Can you use a view controller created for a xib with storyboards? 注销用户时如何切换 UINavigationController 的根视图控制器 (Swift 5) - How do you switch the root view controller of UINavigationController when signing out the user (Swift 5) 带有 xib 文件的 UINavigationController pushViewController - UINavigationController pushViewController with xib file 在其他xib中创建UINavigationController吗? - Create UINavigationController in other xib? xib中的UINavigationController不显示 - UINavigationController in xib not displaying 如何在UINavigationController中使用UIImagePickerController - How to use a UIImagePickerController with UINavigationController 如何在 SwiftUI 中使用 UINavigationController - how to use UINavigationController in SwiftUI 如何将 UIDocumentPickerViewController 与 UINavigationController 一起使用? - How to use UIDocumentPickerViewController with UINavigationController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM