开发者

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

view1 = [[View1 alloc] init];   //Create the first view
UINavigationController *navigationController1 = [[UINavigationController a开发者_开发问答lloc] 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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜