如何将导航控制器添加到基于视图的应用程序?

时间:2010-09-20 11:58:20

标签: objective-c cocoa-touch uiviewcontroller uinavigationcontroller uitableview

是否可以向继承自UINavigationController而非UIViewController的视图应用添加UITableViewController?怎么做?

2 个答案:

答案 0 :(得分:21)

是的,您可以在任何基于视图的应用程序中使用导航控制器,无论是在根级别(例如在Xcode中创建基于导航的模板时)还是使用TabBar根目录,或者使用任何Root。

一个例子,展示包含导航的模态视图(在我的应用程序中用于显示一系列表单):

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

在另一个例子中,如果你想在根级别拥有它,但没有用导航模板创建应用程序,那么在AppDelegate的didFinishLaunching(...)中:

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

您也可以在Interface Builder中设置它,方法是设置您使用的View控制器的类(UIVavController替换为UINavigationController)。

我希望这能回答你的问题(对前面的讨论感到抱歉)。

答案 1 :(得分:0)

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

的viewcontroller的Container创建的。