5

I use code below, but it is not loaded:

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];
4
  • self.navigationController.navigationController will always be nil. A navigation controller can never be in another navigation controller. Commented Feb 6, 2014 at 17:32
  • It also makes no sense to create and an assign a navigation controller like this in a view controller. Normally you would create the navigation controller at a higher level and set it up with a root view controller. Then when the view controller want to push another view controller (like here), you simply push the new view controller onto self.navigationController. Commented Feb 6, 2014 at 17:34
  • without it, it not shows too.. Commented Feb 6, 2014 at 17:35
  • You should read the "View Controller Programming Guide for iOS". Commented Feb 6, 2014 at 17:35

2 Answers 2

8

try as below

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];
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I looked at a lot of issues, but only this answer helped me :) Works at iOS 9.
I'm getting the next error:'release' is unavailable: not available in automatic reference counting mode
3

Add this code to your AppDelegate.m in the didFinishLaunchingWithOptions function:

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 is the .h and .m file name that is linked to your viewController.

YOUR_STORYBOARD_NAME is the name of your .storyboard file. For example, fill in Main if your .storyboard file is called Main.storyboard.

YOUR_VIEWCONTROLLER_ID is the ID for your veiwController. You can edit it in the Identity inspector.(See photo)

Hope this helps:)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.