如何在tabViewController中添加选项卡视图和切换选项卡视图?

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    let newItem: NSTabViewItem = NSTabViewItem(identifier: "abc")
    let tv: NSTextView = NSTextView(frame: NSZeroRect)
    newItem.view?.autoresizesSubviews = true
    newItem.view?.addSubview(tv)
    newItem.label = "Untitled"
    //tabView.addTabViewItem(newItem)
    //tabView.selectTabViewItem(newItem)
    //tabView.insertTabViewItem(newItem, atIndex: 3)
    //tabView.selectFirstTabViewItem(IspViewController)

}

最佳答案

我们应该将NSViewController设置为createdNSTabViewItem

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    let newItem: NSTabViewItem = NSTabViewItem(identifier: "abc")
    newItem.label = "Untitled"
    // "tvcontroller" is in storyboard
    newItem.viewController = storyboard?.instantiateControllerWithIdentifier("tvcontroller") as? NSViewController

    addTabViewItem(newItem)
}

关于xcode - 我应该如何在Swift OS X中添加标签 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33886651/

10-10 20:07