在App Delegate中以root身份设置特定视图控制器

时间:2015-01-29 21:18:54

标签: ios objective-c cocoa-touch

我想知道如何在我的Xcode项目中设置应用程序委托,以便通用视图控制器文件(ViewController.h和.m)将是控制我在我的应用程序委托中设置的根视图控制器的文件。

我的AppDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    CGRect  rect = [[UIScreen mainScreen] bounds];

    self.window.frame = rect;

    planet3dController *theController;
    self.controller = theController;

    self.window.rootViewController = self.controller;

    GLView *glView = [[GLView alloc] initWithFrame:rect];
    [self.window addSubview:glView];

    theController.view=glView;

    glView.controller = self.controller;
    glView.animationInterval = 1.0 / kRenderingFrequency;
    [glView startAnimation];

    glView.layer.contentsScale = [UIScreen mainScreen].scale;

    return YES;
}

1 个答案:

答案 0 :(得分:1)

self.window.rootViewController = self.controller;

看起来你已经在做那件事了。

我不知道您的应用尝试做什么,但[self.window addSubview:glView];有点可疑。您可能希望将glView添加为rootViewController的子视图,而不是窗口,对吧?

如果你想要最初的"泛型"将控制器文件视为rootViewController,然后不要使用您在示例中正在执行的专用planet3dController覆盖它,而是将其设置为该控制器的实例。

相关问题