0

我正在开发我的第一个 Cocoa Mac OS X 程序,并且想知道显示窗口的最佳方法。

我将AppController/MainMenu.xib作为主启动窗口,但 MainMenu.xib 窗口未选中Visible At Launch。我这样做是因为在应用程序加载时我正在检查他们是否已登录。如果没有,我想显示Login.xib窗口而不是MainMenu.xib. 登录后,我会打开MainMenu.xib窗口并关闭LoginController我在- (void)applicationDidFinishLaunching:(NSNotification *)aNotification方法中有这个。

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSLog(@"app delegate");
    [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"]]];
    BOOL didAuth = NO;
    GTMOAuth2Authentication *auth = [GTMClasses authForService];
    if (auth) {
        didAuth = [GTMOAuth2WindowController authorizeFromKeychainForName:kKeychainName authentication:auth];
    }

    if (didAuth) {
        [[DataClass sharedInstance] setIsSignedIn:YES];
        NSLog(@"Already signed in %@", auth);
        NSLog(@"Window: %@", self.window);
        // SHOW MainMenu.xib here
    } else {
        NSLog(@"Not signed in %@", auth);
        loginController = [[LoginController alloc] initWithWindowNibName:@"Login" owner:self];
        [[loginController window] makeKeyAndOrderFront:self];
    }
}
  1. 我看到 AppControllerawakeFromNibapplicationDidFinishLoadingWithOptions. 最好把那个代码放在我的awakeFromNib?
  2. 如果没有,从 AppDelegate 打开 MainMenu.xib 窗口的最佳方法是什么?
  3. 如果你有更好的方法,那会是什么?

PS:AppController 是的子类,NSObject所以我无权访问windowDidLoadwindowWillLoad

4

1 回答 1

1

awakeFromNib是第一个被执行的方法。

也可以使用allocorinit方法。

您可以将您的登录验证码放在那里,没有任何问题。

您一定已经了解了应用程序的生命周期,以及加载哪些方法的方式和时间。

在此处输入图像描述

于 2013-03-11T18:19:08.157 回答