xcode - 傻瓜式界面生成器 : How to set an action to an UIBarButtonItem in Xcode 4?

标签 xcode interface-builder

我正在尝试为 MainWindow.xib 中的 UIBarButtonItem 设置操作。我一直兜圈子,却一无所获。我的 Controller 层次结构如下:

UITabBarController
    UITabBar
    UINavigationController
        UINavigationBar
        UIViewController
            UINavigationItem
                UIBarButtonItem // THIS
        UITabBarItem

如何设置它的操作?我在 IB 中看到一个“选择器”选项,但我不知道如何设置它。

最佳答案

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

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

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

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

- ( IBAction )myMethod: ( id )sender;

发送者对象将是触发操作的对象,在您的例子中是 UIBarButtonItem。

关于xcode - 傻瓜式界面生成器 : How to set an action to an UIBarButtonItem in Xcode 4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5385461/

相关文章:

cocoa - NSTableHeaderView 防止自动布局在分割 View 中调整 ScrollView 的大小

ios - UITableView 中所有单元格的模糊效果背景

ios - Storyboard中带有嵌入式导航 Controller 的 UINavigationBar 自定义颜色

interface-builder - 使用 NSArrayController 添加对象时使 NSTableView 行可编辑

ios - 将 UIStackView 与具有动态高度的 UITextView 结合使用

iphone - 如何在 UILabel 中换行

ios - 使用 Shenzhen 和 Xcode 6 创建构建文件失败

ios - 如何让 iTunes Connect 识别新的 Bundle ID

ios - self.navigationController 分配为 RootViewController 后为空?

iphone - 哪个 GUI 类似于 iphone 上的列表框?