Mvc Cocoa: How to get controller object for UIBarButtonItem target in view?
- by plehoux
I got a basic application where I want the action method of UIBarButtonItem to be in the parent controller. My view has been created programmatically, so I can't use IBAction.
RootViewController - NavigationViewController - NavigationView - UIBarButtonItem
Here's how have done it for the moment, it works for now... but it's not a really scalable technic (in NavigationView.m):
BookAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UIBarButtonItem *soundEffects = [[UIBarButtonItem alloc] initWithTitle:@"Sound Effects"
style:UIBarButtonItemStyleBordered
target:[delegate.rootViewController navigationViewController]
action:@selector(soundEffectsClicked:)];
What would be a better technic to get the NavigationViewController object?