我试图在appDelegate类上加载ViewController。像这样:
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var viewController = HomeViewController()
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.window.backgroundColor = NSColor(rgba: "#02303A")
self.viewController.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame))
self.window.contentView?.addSubview(self.viewController.view)
}
}
我的视图控制器非常简单,只需:
import PureLayout
class HomeViewController : NSViewController {
let search : NSSearchField = {
let search = NSSearchField.newAutoLayoutView()
return search
}()
override func loadView() {
super.loadView()
self.view.layer?.backgroundColor = NSColor.blackColor().CGColor
self.view.addSubview(search)
}
}
但是当我编译项目时,日志返回:
包含完整源代码的存储库:Github
任何人都知道可以做什么?我在我的iOS项目上这样做,它工作正常。