I'm developing an application with a NSSplitView in the main NSWindowController which is organized like that:
a menu on the left panel, which contains an outlineView with many choices and a detailView on the right panel which corresponds to the item choosen in the left panel.
In the main NSWindowController, I have a toolbar with Buttons (that's the important point)
Then I click on an item in the left panel, I have the following action:
func outlineViewSelectionDidChange(_ notification: Notification) {
let outline = notification.object as! NSOutlineView
let item = outline.item(atRow: outline.selectedRow)
if item is MenuSocietes {
if vc != nil {
splitView.removeArrangedSubview((splitView?.subviews[1])!)
vc = nil
}
vc = societesController()
contentViewController?.presentAsModalWindow(vc)
if splitView.subviews.count > 1 {
splitView.removeArrangedSubview((splitView?.subviews[1])!)
}
splitView.addSubview(vc.view)
} if item is MenuImmeuble {
if vc != nil {
splitView.removeArrangedSubview((splitView?.subviews[1])!)
vc = nil
}
vc = immeubleController((item as! MenuImmeuble).id)
contentViewController?.presentAsModalWindow(vc)
if splitView.subviews.count > 1 {
splitView.removeArrangedSubview((splitView?.subviews[1])!)
}
splitView.addSubview(vc.view)
} else {
if vc != nil {
splitView.removeArrangedSubview((splitView?.subviews[1])!)
vc = nil
}
}
}
Of course this is just a example (a little dirty, I know).
societesController and immeubleController are NSViewControllers.
Now I want my detailView (in the above code, societesController or immeubleController) to interact with the NSToolbar of the main NSWindowController.
It would be easy to pass this toolbar as a parameter in the init code of my details NSViewController, but I'm not sure it's the finest way.
I try to find, in my viewControllers (societesController and immeubleController) the ancestor, doing something like this:
var _parent = presentingViewController
while _parent != nil {
Swift.print(_parent?.className)
_parent = _parent!.parent
}
the first line return nil as _parent. Am I missing something?