Mvc Cocoa: How to get controller object for UIBarButtonItem target in view?

Posted by plehoux on Stack Overflow See other posts from Stack Overflow or by plehoux
Published on 2010-05-26T18:29:05Z Indexed on 2010/05/26 18:31 UTC
Read the original article Hit count: 245

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about mvc