views:

577

answers:

3
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

A: 

You may have things a little mixed up. A UINavigationController is generally attached to a UIViewController, which itself is what contains the UIView.

Before writing your own code, you might take a look at the navigation controller sample application project that is available from Xcode's new project template list, to figure out how it works.

Alex Reynolds
+1  A: 

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.

jkeesh
You can init with the root view: UINavigationController * navigation = [[UINavigationController alloc] initWithRootViewController: yourViewController];
Luke Mcneice
A: 

The answer for this question is here: http://stackoverflow.com/questions/2282192/having-problem-with-pushviewcontroller-help

Harry Pham