xcode 如何在故事板中以编程方式设置导航控制器动画的根视图控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27721885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:26:11  来源:igfitidea点击:

How to set root view controller in storyboard animated with navigation controller programmatically

iosobjective-ciphonexcode

提问by moeen

I have my login screen how ever i can able to skip that screen and go to home page when I am in the home page I could`d able to get my navigation controller in my home page i have embedded navigation controller with my login page have connectivity via push segue to home page every thing is good but nav bar is not coming in homepage if I try to embedded nav controller in homepage then also its not coming ... my code is

我有我的登录屏幕,当我进入主页时,我如何能够跳过该屏幕并转到主页 我可以在我的主页中获取我的导航控制器 我在我的登录页面中嵌入了导航控制器通过 push segue 连接到主页,一切都很好,但是如果我尝试在主页中嵌入导航控制器,导航栏不会出现在主页中,那么它也不会出现......我的代码是

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
     NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];

     if (![defaults boolForKey:@"registered"])

     {   NSLog(@"no user register ");
     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
     ViewController *secondViewController = [storyBoard instantiateViewControllerWithIdentifier:@"LoginPage"];
     self.window.rootViewController = secondViewController;
     // then set your root view controller

     }

     else

     {   NSLog(@"user is daam sure registered");


     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] ;
         ;
     ABDB_CAMERAHOME *mainviewcontroller = [storyBoard instantiateViewControllerWithIdentifier:@"CameraHome"];

              self.window.rootViewController = mainviewcontroller;
     }

    return YES;
}

is their I am missing constraint about nav controller in program please suggest

我在程序中缺少有关导航控制器的约束吗?请提出建议

采纳答案by Rigel Networks

User following method to set rootViewController using navigation:

用户使用导航设置 rootViewController 的以下方法:

[(UINavigationController*)self.window.rootViewController pushViewController:yourViewController animated:YES];

回答by NewStackUser

In latest Xcode 6.1 in storyboards their are settings for navigation controller bar visibility. You can tick the "Shows Navigation Bar" for display.

在故事板的最新 Xcode 6.1 中,它们是导航控制器栏可见性的设置。您可以勾选“显示导航栏”进行显示。

回答by NewStackUser

In your appDelegate.h add below property and synthesize in .m

在您的 appDelegate.h 添加以下属性并在 .m 中合成

@property(strong,nonatomic)UINavigationController *navigationController;

@property(strong,nonatomic)UINavigationController *navigationController;

@synthesize navigationController;

now modify app delegate as below

现在修改应用程序委托如下

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    if (![defaults boolForKey:@"registered"])
    {   NSLog(@"no user register ");
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        ViewController *secondViewController = [storyBoard instantiateViewControllerWithIdentifier:@"LoginPage"];
        self.navigationController=[[UINavigationController alloc]initWithRootViewController:secondViewController];
        self.window.rootViewController = self.navigationController;
        // then set your root view controller
    }

    else

    {   NSLog(@"user is daam sure registered");
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] ;
        ;
        ABDB_CAMERAHOME *mainviewcontroller = [storyBoard instantiateViewControllerWithIdentifier:@"CameraHome"];
        self.navigationController=[[UINavigationController alloc]initWithRootViewController:mainviewcontroller];
        self.window.rootViewController = self.navigationController;
    }

    return YES;
}

Once all is set, check your storyboard whether you have mentioned proper xib identifier names over there? Also if you have used any navigation controller there, remove that also. Now clean the project from build setting and re-run.

一切就绪后,检查您的故事板是否在那里提到了正确的 xib 标识符名称?此外,如果您在那里使用过任何导航控制器,也请将其删除。现在从构建设置中清除项目并重新运行。