ios - 一个 BarButtonItem 的多个操作

标签 ios uinavigationcontroller uibarbuttonitem

我正在尝试将两个操作分配给一个 BarButtonItem,但语法 (bad receiver type 'NSInteger' aka 'long') 有问题,我无法编译我的应用程序。这是错误的代码:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(myAction1)];
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(myAction2)];

我正在使用 Xcode 5.1,我的目标是 iOS 7.0。

你能帮帮我吗?提前谢谢你。

最佳答案

您不能将两个操作分配给 BarButtonItem

您可以在 selector 方法中调用第二个操作。

或者您可以简单地删除以前的目标并在运行时有条件地添加新的目标操作

关于ios - 一个 BarButtonItem 的多个操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22659799/

相关文章:

ios - 关闭导航 View Controller

ios - 弹出到 View Controller

ios - bar按钮项目文本在moonIcon中选择时会改变,就像swift 4中的Font Awesome一样

ios - 如何从 iOS 应用程序使用 Branch.io DeepLink 打开我们的另一个 iOS 应用程序

objective-c - 方向改变时的 UIScrollview 内容大小

iphone - 我目前有一个加速计 Action ,可以显示图像但不会清除/重置

iphone - 如何在 iPhone 中使用移动和缩放 UIImagePickerController?

ios - 关于 leftBarButtonItem 没有以编程方式出现

ios - 获取 UIBarButtonItem 的坐标或 CGPoint

ios - 如果字符串值之一包含 ("),则 Swift Codable 无法解码