Interface Builder for Dummies:如何在Xcode 4中为UIBarButtonItem设置动作?

时间:2011-03-22 00:43:34

标签: xcode interface-builder

我正在尝试为我的MainWindow.xib中的UIBarButtonItem设置操作。我一直在四处走动,我没有到达任何地方。我的控制器层次结构如下:

UITabBarController
    UITabBar
    UINavigationController
        UINavigationBar
        UIViewController
            UINavigationItem
                UIBarButtonItem // THIS
        UITabBarItem

如何设置动作?我在IB中看到了一个“选择器”选项,但我不确定如何设置它。

1 个答案:

答案 0 :(得分:6)

因此,根据您的评论回答,您必须使用targetaction属性。

目标是将接收操作的对象。 Action是目标对象的选择器(方法)。

myBarButtonItem.target = self;
myBarButtonItem.action = @selector( myMethod: );

记住动作方法必须具有以下签名:

- ( IBAction )myMethod: ( id )sender;

发件人对象将是触发操作的对象,在您的情况下是UIBarButtonItem。