I have a basic Cocoa app to try out Swift and Storyboards.
The app consists of 3 main views that are managed by an NSTabViewController
, which again is linked to the main window's "window content" relationship.
I added an NSSegmentedControl
to the window's toolbar to switch between the 3 tab views.
In the main window controller I added the action method for the toolbar item to switch between the tabs, but I can't figure out how to get a reference to the tab view controller to actually switch tabs.
I tried adding my action method to the tab view controller, but that does not work, because the tab view controller might not be in the responder chain if it contains an empty view (is this a bug?).
As a workaround, I overrode viewDidAppear() in the tab view controller. There I get a handle to the view.window.windowController and set a reference to "self" in an instance variable. This works, but does not seem right. There should be a way to get from the window controller to it's content view controller...
The window controller and tab view controllers live in different scenes, to I can't connect them through IBOutlet. Also, none of the segue methods are called on the window controller either for the "window content" relationship.
I'm mainly an OS X guy, and I'm new to StoryBoards myself, but I think what you need to do is:
Write your
-(IBAction)someResponse:(id)sender {}
method in the view controller that plans to handle the action.