从viewDidLoad获取UIButton参考 [英] Get UIButton reference from viewDidLoad
问题描述
我对iPhone开发非常陌生.我试图禁用一个已经存在的按钮,但实际上无法获得指向视图中特定元素的指针.例如,我在viewController标头中有以下内容
I am very new to iPhone development. I am trying to disable an already existing button but I cant actually obtain a pointer to a specific element in the view. For instance, I have the following in the viewController header
- (IBAction)one:(id)sender;
实现是
- (IBAction)one:(id)sender {
}
这只是事件处理程序.但是,当视图打开时,我需要禁用该按钮,而在如何获取对事件处理程序外部元素的引用时,我有些迷失了.
which are just event handlers. However, I need disable the button when view opens and I am a little bit lost on how to obtain references to elements outside of the event handler.
所以换句话说,我的想法是像这样:
So in other words, my thought is to have something like:
UIButton* myButton = //something
哪里有什么东西让我迷失在做什么上.有任何想法吗?我非常感谢我在这里获得的任何帮助!
where the something is where I am lost on what to do. Any ideas? I greatly appreciate any help I get on here!
推荐答案
您需要在界面中为按钮创建一个属性:
You need to create a property for your button in the interface:
@property(nonatomic, retain) IBOutlet UIButton * button;
并将其添加到实现中
@synthesize button;
然后在界面生成器中将按钮连接到它.之后,您可以通过以下方式禁用按钮:
Then connect the button to it in interface builder. After this you can disable the button by:
button.enabled = NO;
希望我能帮上忙!
这篇关于从viewDidLoad获取UIButton参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!