使用故事板以编程方式创建导航栏 [英] Creating Navigation Bar programmatically with storyboard
本文介绍了使用故事板以编程方式创建导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
UINavigationController *navVC = [UINavigationController new];
ViewController *VC1 = [ViewController new];
[window makeKeyAndVisible];
[navVC setViewControllers:[NSArray arrayWithObject:VC1] animated:NO];
[window setRootViewController:navVC];
return window;
}
调用此方法时,我得到了导航栏,但在情节提要的 ViewController 视图中看不到我的内容.我不知道我做错了什么,我试过添加子视图和东西,但没有任何效果.有谁知道我做错了什么?
When calling this method, I get my Nav Bar but I don't see what i have in my ViewController view in the storyboard. I can't figure out what i'm doing wrong though, i've tried adding subview and stuff but nothing works out. Does anyone know what i am doing wrong?
推荐答案
你需要写这段代码,而不是你写的东西
you need to write this code instead of what you have written
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self. window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
UINavigationController *navVC = [UINavigationController new];
UIStoryboard *mStoryboard = [UIStoryboard storyboardWithName:@"your storyboard name" bundle:nil];
ViewController *VC1 = [mStoryboard instantiateViewControllerWithIdentifier:@"VC"];
[navVC setViewControllers:[NSArray arrayWithObject:VC1] animated:NO];
[self. window setRootViewController:navVC];
[self. window makeKeyAndVisible];
return YES;
}
这篇关于使用故事板以编程方式创建导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文