【发布时间】:2014-12-01 12:24:32
【问题描述】:
我正在尝试使用 swift for OS X 从笔尖添加新的子视图。
到目前为止,我已经:
- 创建了一个新的“Cocoa 应用程序”
- 添加了一个名为“TestSubView”的新“Cocoa 类”作为带有 XIB 文件的 NSViewController 的子类
我想在应用程序加载时将此子视图添加到我的主视图中。
在我的 ViewController(主窗口的 ViewController)中。
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let newSubView = TestSubView();
self.view.addSubview(newSubView.view);
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
但我收到以下错误
Failed to set (contentViewController) user defined inspected property on (NSWindow):
-[NSNib initWithNibNamed:bundle:] could not load the nibName: temp.TestSubView in bundle (null).
我意识到我需要调整这个子视图的大小和位置,但我似乎无法做到这一点。
我花了一天的大部分时间试图弄清楚这一点,所以任何帮助都将不胜感激。
【问题讨论】:
标签: xcode macos cocoa swift nsviewcontroller