gpt4 book ai didi

swift - 从 windowDidLoad 启动 ViewController 作为工作表

转载 作者:行者123 更新时间:2023-11-28 07:48:57 24 4
gpt4 key购买 nike

我试图在窗口加载后立即将 Storyboard显示为工作表。

override func windowDidLoad() {
super.windowDidLoad()
let storyboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Init"), bundle: nil)
let controller = storyboard.instantiateInitialController() as! NSViewController
self.window!.contentViewController?.presentViewControllerAsSheet(controller)
}

不幸的是,工作表显示错位并位于窗口后面。当我在按钮内运行相同的代码时,一切正常。

Screenshot

如何在加载窗口后正确显示 Storyboard 表?

最佳答案

我对 iOS 生态系统有更多了解,但我认为您应该仅在显示原始窗口后才显示新窗口。 windowDidLoad 在加载 View 时调用,而不是在显示 View 时调用。

因此,您可能应该将代码放入 contentViewControllerviewDidAppear 中。

关于swift - 从 windowDidLoad 启动 ViewController 作为工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50199360/

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