Interface Builder for Dummies: How to set an action to an UIBarButtonItem in Xcode 4?
I am trying to set the action for a UIBarButtonItem I have in my MainWindow.xib. I keep going round and round and I'm not getting anywhere. My controller hierarchy is as follows:
UITabBarController
UITabBar
UINavigationController
UINavigationBar
UI开发者_开发百科ViewController
UINavigationItem
UIBarButtonItem // THIS
UITabBarItem
How can I set the action to it? I see a "selector" option in IB, but I'm not sure how to set it.
So, based on your comment answer, you'll have to use the target
and action
properties.
Target is the object that will receive the action. Action is a selector (a method), from the target object.
myBarButtonItem.target = self;
myBarButtonItem.action = @selector( myMethod: );
Remember action method must have the following signature:
- ( IBAction )myMethod: ( id )sender;
The sender object will be the object that triggered the action, in your case the UIBarButtonItem.
精彩评论