我正在尝试为 MainWindow.xib 中的 UIBarButtonItem 设置操作。我一直兜圈子,却一无所获。我的 Controller 层次结构如下:
UITabBarController
UITabBar
UINavigationController
UINavigationBar
UIViewController
UINavigationItem
UIBarButtonItem // THIS
UITabBarItem
如何设置它的操作?我在 IB 中看到一个“选择器”选项,但我不知道如何设置它。
最佳答案
因此,根据您的评论答案,您必须使用 target
和 action
属性。
目标是将接收操作的对象。 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/