gpt4 book ai didi

objective-c - 正确使用窗口

转载 作者:行者123 更新时间:2023-12-03 17:54:40 25 4
gpt4 key购买 nike

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

我将 AppController/MainMenu.xib 作为主启动窗口,但未选中 MainMenu.xib 窗口的启动时可见。我这样做是因为在应用程序加载时我会检查它们是否已登录。如果没有,我想显示 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. 我看到 AppController 的 awakeFromNibapplicationDidFinishLoadingWithOptions 之前被调用。最好将该代码放入我的 awakeFromNib 中吗?
  2. 如果没有,从 AppDelegate 打开 MainMenu.xib 窗口的最佳方式是什么?
  3. 如果您有更好的方法,会是什么?

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

最佳答案

awakeFromNib 是第一个执行的方法。

您还可以使用 allocinit 方法。

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

您一定已经了解了应用程序的生命周期、如何以及何时加载哪些方法。

enter image description here

关于objective-c - 正确使用窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com