开发者

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 targetand 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜