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

痞子三分冷 提交于 2019-12-20 10:58:22

问题


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


回答1:


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).




回答2:


I created a sample code to understand how to build a UITabBarController which is create with Container of viewcontroller including several navigationcontroller https://github.com/damienromito/CustomTabBarController



来源:https://stackoverflow.com/questions/3751235/how-to-add-a-navigation-controller-to-a-view-based-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!