Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a UINavigationController to a view in code?

view1 = [[View1 alloc] init];   //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];

View1 is inherit from UIViewController. So I create a *view1, then I create a UINavigationController, call *navigationController1. How do I link the two together? Thank you very much

like image 837
Thang Pham Avatar asked Dec 30 '22 01:12

Thang Pham


1 Answers

The way to link a view controller with a navigation controller is to push the view controller onto the navigation stack. For example:

UIViewController * yourViewController = [[UIViewController alloc] init];
UINavigationController * navigation = [[UINavigationController alloc] init];
[navigation pushViewController:yourViewController animated:NO];
[yourViewController release]

Finally release the view controller at the end since the navigation controller retains it.

like image 82
jkeesh Avatar answered Jan 04 '23 23:01

jkeesh