[英]How to set root view controller in storyboard animated with navigation controller programmatically
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 我有登录屏幕,但是当我进入主页时,如何能够跳过该屏幕并转到主页?我可以将导航控制器放到主页中。我在登录页面中嵌入了导航控制器,通过推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 是他们我在程序中缺少有关导航控制器的约束,请提出建议
In latest Xcode 6.1 in storyboards their are settings for navigation controller bar visibility. 在情节提要中的最新Xcode 6.1中,它们是导航控制器栏可见性的设置。 You can tick the "Shows Navigation Bar" for display. 您可以勾选“显示导航栏”进行显示。
In your appDelegate.h add below property and synthesize in .m 在您的appDelegate.h中添加以下属性并在.m中进行合成
@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? 设置完所有内容后,请检查您的情节提要中是否提到了正确的Xib标识符名称? Also if you have used any navigation controller there, remove that also. 另外,如果您在那里使用了任何导航控制器,也请删除它。 Now clean the project from build setting and re-run. 现在,从构建设置中清除项目,然后重新运行。
用户使用以下方法通过导航设置rootViewController:
[(UINavigationController*)self.window.rootViewController pushViewController:yourViewController animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.