问题描述
我有一个不想被禁用的UIBarButtonItem。简短版本:当我打电话时
I have a UIBarButtonItem that just doesn't want to get disabled. Short version: when I call
[myBarButtonItem setEnabled:NO];
没有任何反应。
myBarButtonItem
是 myVIewController
中的IBOutlet。 myViewController
已作为对象添加到Interface Builder中的 MainWindow
。 myBarButtonItem
出口已连接到BarButtonItem,并具有相应的 @syntesize
和属性
行设置。
myBarButtonItem
is an IBOutlet in myVIewController
. myViewController
has been added as an object to MainWindow
in Interface Builder. The myBarButtonItem
outlet has been connected to the BarButtonItem, and has the corresponding @syntesize
and property
lines set.
@property (nonatomic, retain) IBOutlet UIBarButtonItem *myBarButtonItem;
在myViewController.m中,
In myViewController.m,
@synthesize myBarButtonItem;
任何人都知道为什么以上 setEnabled
方法没有影响?谢谢!
Anyone have an idea why the above setEnabled
method has no affect? Thanks!
更新:修正了!不知道为什么,但显然出口没有设置。我使用我的App Delegate作为UIBarButtonItem的父对象,并且一切顺利。
UPDATE: Fixed it! Don't know why, but apparently the outlet wasn't being set. I used my App Delegate as the parent object for the UIBarButtonItem, and all worked out.
推荐答案
您可以禁用左侧导航按钮从这样的UIViewController里面,不使用任何IBOutlet:
You can disable the left navigation button from inside an UIViewController like this, without using any IBOutlet:
self.navigationItem.leftBarButtonItem.enabled = NO;
要禁用右侧导航按钮:
self.navigationItem.rightBarButtonItem.enabled = NO;
Swift3
self.navigationItem.rightBarButtonItem?.isEnabled = false
这篇关于如何禁用UIBarButtonItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!