Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add navigation controller programmatically?

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];
like image 694
user3267017 Avatar asked Feb 06 '14 17:02

user3267017


People also ask

How do I push navigation controller?

To push UINavigationController , first create a subclass of UIViewController , which will be a wrapper-/container- class for your UINavigationController and its content. This is a much more comprehensive answer which addresses the need to support hierarchical navigation controllers without modal presentation.

How do I add a navigation controller to my storyboard?

Under the View menu, select Utilities→Show Object Library. In the Object Library, find the Navigation Controller object (see Figure 4-7) and drag and drop it into the storyboard, to the left side of your existing view controller (Figure 4-6).


1 Answers

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];
like image 198
freelancer Avatar answered Oct 16 '22 17:10

freelancer