Search code examples
cocoaswift3nstabviewcontroller

Cocoa disable tabItem at index


I have a NSTabViewController which has two NSTabViewItem. I want to disable second tab.

class MainTabViewController: NSTabViewController {

// Properties
var data : [String: AnyObject]?


override func viewDidLoad() {
    super.viewDidLoad()
    let tabItem = self.tabView.tabViewItem(at: 1)
    tabItem.isSelectable = true


   }

}

as tabItem.isSelectable is a get only property, how can I disable and enableNSTabViewItem item.


Solution

  • You need to set the delegate for your tab view and implement func tabView(NSTabView, shouldSelect: NSTabViewItem?) method to return false if you need to disable a specific NSTabViewItem.