gpt4 book ai didi

macos - viewDidLoad 未触发

转载 作者:行者123 更新时间:2023-12-03 17:02:29 27 4
gpt4 key购买 nike

全部,
我正在从我的 applicationDidFinishLaunching 方法创建一个 windowController ...

(void)applicationDidFinishLaunching:(NSNotification *)aNotification {
myWC = [[myWindowController alloc] initWithWindowNibName:@"myWindowControllerName"];

[myWC showWindow:self];
}

此时会调用windowDidLoad方法。从那里,我调用该方法来加载 viewController...

(void)windowDidLoad {
[super windowDidLoad];

homeScreenVC = [[HomeScreen alloc] initWithNibName:@"HomeScreen" bundle:nil];

[baseView addSubview:[homeScreenVC view]];
}

当 View 出现时,不会调用 viewDidLoad 方法。我尝试了 viewDidAppear 但也没有被调用。我还尝试在加载窗口后立即加载 viewController,但这也不起作用。有任何想法吗?

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

对于 OSX,您应该使用 loadView

<小时/>

编辑:您可以从 appDelegate 加载您的节目 homeScreenVC:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
homeScreenVC = [[HomeScreen alloc] initWithNibName:@"HomeScreen" bundle:nil];
[self.window.contentView addSubview:self.homeViewController.view];
homeScreenVC.view.frame = ((NSView*)self.window.contentView).bounds;
}

这里不要加载 View ,加载 View 时会调用此方法

-(void)loadView{
[super loadView];
//anything you want to do when home screen is presented
}

关于macos - viewDidLoad 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28205718/

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