如何以编程方式初始化UINavigationController的子类?

时间:2014-05-20 14:00:00

标签: ios objective-c xcode

我正在读一本教我实施#GameCenter"的书,但这是一个问题。我没有在其中使用故事板,而教程也是如此。它说要转到故事板中导航控制器的身份检查员并放入自定义类。我想知道如何在不使用故事板的情况下以编程方式执行此操作。

我知道最接近的事情就是这个,但我很确定这是错的:

代码:

NavigationController *navigationController = [[NavigationController alloc] init];

2 个答案:

答案 0 :(得分:1)

AppDelegate.m找到此方法

    -(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)options
    {
// create your custom class and assign a rootViewController. In your case your existing root controller
      NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:self.window.rootViewController];

//Change your existing rootViewController to your custom one
      [self.window setRootViewController:navigationController];


      return YES;
    }

你们都完成了!

答案 1 :(得分:0)

您需要将UINavigationController的子类的.h导入到您正在使用的任何文件中,例如

#import "CustomNavController.h"

然后,如果你想创建和自定义导航控制器的实例,你会去

CustomNavController *navigationController = [[CustomNavController alloc] init];

我不确定你要用它做什么,但希望你需要知道这些。