更改初始化时位于情节提要中的 UINavigationController 的 rootviewcontroller [英] changing rootviewcontroller of a UINavigationController which is in storyboard while its initialised
问题描述
我在故事板中有一个 UINavigationController
控制器,它是入口点,它的类是 MyNavigationController
.我没有从故事板将 rootviewcontroller
分配给 UINavigationController
,但想从 MyNavigationController
分配相同的内容,从一些初始化方法请帮助我如何做到这一点还是不可能?.
I have a UINavigationController
controller in the story board which is the entry point,whose class is MyNavigationController
.
I have not assigned the rootviewcontroller
to the UINavigationController
, from the story board ,but want to assign the same from MyNavigationController
,From some initialize methods
Please help me how to do that or is it impossible?.
推荐答案
choice-1
您可以识别您的 Stroryboard ID 并设置为 Root
you can Identify your Stroryboard ID and set as Root
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginSignupVC"];
[[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController];
}
选择 2
初始视图控制器会自动识别您的根控制器
the Initial View COntroller automatically identify your Root controller
您可以使用属性在您的视图控制器上识别您的 Stroryboard ID
you can Identify your Stroryboard ID on your viewcontroller using Attribute
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyNavigationController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginSignupVC"];
[[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController];
}
选择 3
xcode --> 菜单 -> 编辑器 -> embedIn -> NavigationController
xcode --> Menu -> editor -> embedIn -> NavigationController
你可以得到如下输出
它会自动找到您的根控制器
it find automatically your root controller
这篇关于更改初始化时位于情节提要中的 UINavigationController 的 rootviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!