Thang Pham
Thang Pham

Reputation: 38695

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

Upvotes: 4

Views: 22405

Answers (3)

Thang Pham
Thang Pham

Reputation: 38695

The answer for this question is here: Having problem with pushViewController!! Help

Upvotes: 0

jkeesh
jkeesh

Reputation: 3339

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.

Upvotes: 10

Alex Reynolds
Alex Reynolds

Reputation: 96994

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.

Upvotes: 0

Related Questions