我正在开发我的第一个 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];
}
}
- 我看到 AppController
awakeFromNib
在applicationDidFinishLoadingWithOptions
. 最好把那个代码放在我的awakeFromNib
? - 如果没有,从 AppDelegate 打开 MainMenu.xib 窗口的最佳方法是什么?
- 如果你有更好的方法,那会是什么?
PS:AppController 是的子类,NSObject
所以我无权访问windowDidLoad
或windowWillLoad