How to add navigation controller programmatically?
13,859
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
And in NewViewController: USe this to dismiss and get back to previous view.
[[self navigationController] dismissModalViewControllerAnimated:YES];
Comments
-
CKT almost 2 years
In my app there is requirement that..I have 6 buttons in a nib, when I press any button a new nib will be loaded into the window according to the button pressed. problem is after loading the new nib If I want to come back to the previous nib (which is having all the buttons) how to add navigation controller?
what I am doing now is while loading the new nib when I pressed the button
objNewViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil]; [self.navigationController pushViewController:objNewViewController animated:YES];
but by this way im not able to load the nib, it's not performing any operation?
-
CKT about 14 yearsthank you for the reply johan.. but the thing is the nib which is having these 5 to 6 buttons is not the first nib.. i have 2 nibs before this..after that this buttons nib will come. here i cant take the navigation controller especially rite? that why i wanna add the navigation controller programatically atleast to come back till the nib which contains the buttons.
-
Johan Kool about 14 yearsIn that case, create the UINavigationController using its designated initializer (-init...) and add its view when you need it. You can the push other viewcontrollers on its stack after you've created them with -initWithNib...
-
CKT about 14 yearswhen I do this it is loading my newViewController's nib, but the problem is it doesnt have any back button to come back. how to solve this?
-
Manjunath about 14 yearsyou can add leftBarButton to navigation item. Add cancel button and in its action method, dismiss the model.
-
Mayank over 10 years
presentModalViewController
is deprecated from iOS 6.0. What can be the alternative of this.