gpt4 book ai didi

macos - 使用 Swift 从 Nib 创建 View Controller

转载 作者:搜寻专家 更新时间:2023-10-31 21:49:07 26 4
gpt4 key购买 nike

我正在尝试按照本教程进行操作: http://www.raywenderlich.com/17811/how-to-make-a-simple-mac-app-on-os-x-10-7-tutorial-part-13

但在 Swift 中完成。

尝试执行创建主视图 Controller 步骤我有以下代码:

    import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet var window: NSWindow
@IBOutlet var vc: MasterViewController?

func applicationDidFinishLaunching(aNotification: NSNotification?) {
vc = MasterViewController(nibName: "MasterViewController", bundle: nil)
}

func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}


}

但是在 MasterViewController 实例化时我得到了错误:找不到接受提供的参数的“__conversion”的重载

我做错了什么?

最佳答案

我认为这是一个错误,因为文档说 bundle 可以是 nil 但在 swift 中是不允许的,会抛出该错误。

但是您可以将 NSBundle.mainBundle() 作为 bundle 传递并且它可以工作。

引自 NSViewController 文档:

The bundle in which to search for the nib file. If you specify nil, this method looks for the nib file in the main bundle.

关于macos - 使用 Swift 从 Nib 创建 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24203699/

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