我使用下面的代码,但未加载:
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.mapViewController = [storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self];
self.navigationBar = [[UINavigationBar alloc]init];
[self.view addSubview:self.navigationBar];
[self.navigationController.navigationController pushViewController:self.mapViewController animated:YES];
答案 0 :(得分:9)
尝试如下
UIViewController *bbp=[[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[self.navigationController pushViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];
答案 1 :(得分:2)
将此代码添加到AppDelegate.m
函数中的didFinishLaunchingWithOptions
:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"YOUR_STORYBOARD_NAME" bundle:nil];
yourViewControllerClassName *vc = [sb instantiateViewControllerWithIdentifier:@"YOUR_VIEWCONTROLLER_ID"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
yourViewControllerClassName
是链接到viewController的.h和.m文件名。
YOUR_STORYBOARD_NAME
是.storyboard文件的名称。例如,如果您的.storyboard文件被调用Main
,请填写Main.storyboard
。
YOUR_VIEWCONTROLLER_ID
是您的veiwController的ID。您可以在Identity inspector
中进行修改。(见照片)
希望这会有所帮助:)