iphone - 如何禁用 UIBarButtonItem?

标签 iphone ios

我有一个只是不想被禁用的 UIBarButtonItem。简短版本:当我打电话时

[myBarButtonItem setEnabled:NO];

没有任何反应。

myBarButtonItemmyVIewController 中的一个 IBOutlet。 myViewController 已作为对象添加到 Interface Builder 中的 MainWindowmyBarButtonItem 导出已连接到 BarButtonItem,并设置了相应的 @syntesizeproperty 行。

@property (nonatomic, retain) IBOutlet UIBarButtonItem *myBarButtonItem;

在myViewController.m中,

@synthesize myBarButtonItem;

有人知道为什么上面的 setEnabled 方法没有影响吗?谢谢!

更新:已修复!不知道为什么,但显然没有设置 socket 。我使用我的 App Delegate 作为 UIBarButtonItem 的父对象,一切顺利。

最佳答案

您可以像这样从 UIViewController 中禁用左侧导航按钮,而无需使用任何 IBOutlet:

self.navigationItem.leftBarButtonItem.enabled = NO;

要禁用右侧导航按钮:

self.navigationItem.rightBarButtonItem.enabled = NO;

Swift3

self.navigationItem.rightBarButtonItem?.isEnabled = false

关于iphone - 如何禁用 UIBarButtonItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3784112/

相关文章:

ios - UIBarButtonItem 图像未显示,而是显示红色方 block

ios - Swift UIScrollViewDelegate 不触发 scrollViewDidScroll 事件

iphone - NSDictionary 没有响应 objectForKey 和 valueForKey

iphone - 我可以在 iOS 4 之前的设备上使用 Core Motion 框架吗?

iphone - 我可以在另一个应用程序中拥有一个应用程序吗?

ios - microsoft azure 客户端 swift 库选择 nolock

ios - 切换到新场景时内存会增加

iphone - 尝试调试错误: *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]

iphone - PhoneGap : download & save binary files (mp3s) for iPhone & Android

ios - 取消选择行的适当位置