简体   繁体   中英

How to add a navigation controller to a view-based application?

Is it possible to add a UINavigationController to a view application that inherits from UIViewController and not UITableViewController ? How is it done?

Yes, you can have Navigation controllers in any view based application, whether at the Root level (like when you create the Navigation-based template in Xcode) or with a TabBar root, or with any Root.

One example, presenting a modal view including navigation (used in my app to display a series of forms):

    UIViewController *control = [[MyViewController alloc] initWithNibName: @"MyViewController" bundle: nil];
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
    [self presentModalViewController: navControl animated: YES];
    [control release];

In another example, if you want to have it at the root level, but didn't create the application with the Navigation template, in the AppDelegate's didFinishLaunching(...):

    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
    [window setRootViewController: navControl];
    [navControl release];

You can also set it in Interface Builder, by setting up the class of the View controller you use (UIViewController replaced by UINavigationController).

I hope this answers your question (sorry about the previous discussion).

我创建了一个示例代码,以了解如何构建一个UITabBarController,它是使用包含多个navigationcontroller https://github.com/damienromito/CustomTabBarController的viewcontroller创建的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM