Reputation: 7782
I have a main NSTabViewController
with few tabs:
class MainTabViewController: NSTabViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
print(tabView)// returns <NSTabView: 0x101e17a10> but what to do with it ?
}
}
I want to check in every NSViewController
if variable hasChanges
is true
then pop up message:
"You have unsaved changes. Do you want to change tab ?"
If i check this in MainTabViewController
i get <NSTabView: 0x101e17a10>
and what to do with it i don't know.
If i try to use NSTabViewDelegate
in my MyViewController
then i don't know how to delegate MainTabViewController
in it. Where attach it ?
class MyViewController: HIDNSViewController {
func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
//Never called
}
}
Upvotes: 5
Views: 739
Reputation: 17152
0x101e17a10
is the address of the NSTabView
instance pointed to by the tabView object. You need to print the tabView identifiers within your didSelect method.
You need to set the identifiers in the Interface Builder:
And then (for example):
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
if tabView.selectedTabViewItem?.identifier! as! String == "1" {
print("FIRST VC")
} else {
print("SECOND VC")
}
}
Output when tabbing:
Upvotes: 1