I've a single window Document-based application that loads several NSViewControllers that serve as the main view. Each view controller is a self-contained class that deals with certain business needs and as such implements all methods necessary to work.
My problem is how to make the toolbar work when a specific view controller is loaded. I've no problems wiring the toolbar to a delegate and the toolbar items to actions as long as these are implemented in the window class. But if I try to set a new action for a toolbar item on the loadView
method of a view, the toolbar item simply ignores it and continues calling the method on the main window class.
So, how can I dynamically change the action on a toolbar item?
Are you setting the target as well? (ie [foo setTarget:]
in addition to [foo setAction:]
)
Presumably your window controller has some sort of currentViewController
ivar/property? It might be better not to reassign the toolbar actions when switching view controllers, and instead use the window controller to pass them on the currently active view controller.