启用/禁用 xCode 4.2 中的按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9012100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:06:10  来源:igfitidea点击:

Enable/disable a button in xCode 4.2

xcodebutton

提问by Nick

I've been searching for hours to find the code that enables/disables a button in xCode 4.2

我一直在寻找几个小时来找到在 xCode 4.2 中启用/禁用按钮的代码

I am trying to have an if statement inside a button that it either enables or disables a specific button.

我试图在按钮内使用 if 语句,它可以启用或禁用特定按钮。

I've tried

我试过了

UIButon *buttonName = (UIButton *) sender;
buttonName.enabled = NO;

(I've read this in an another post)

(我在另一篇文章中读过这个)

But the problem with that code is that it disables the button that I have the code inside it and not the button that I want it to disable.

但是该代码的问题在于它禁用了我在其中包含代码的按钮,而不是我希望它禁用的按钮。

回答by Muad'Dib

you have the gist of it...

你有它的要点...

if you have an instance of your button just set the enabled to false.... the example you are showing is for an event handler, so it will disable the button that is sending the message to you.

如果您有一个按钮实例,只需将 enabled 设置为 false .... 您显示的示例是针对事件处理程序的,因此它将禁用向您发送消息的按钮。

in your .h file, you have this button declared and hooked up to your nib:

在您的 .h 文件中,您已声明此按钮并将其连接到您的笔尖:

@property (retain, nonatomic) IBOutlet UIButton *btnMyButton;

now, you can enable/disable like this in your .c file:

现在,您可以在 .c 文件中像这样启用/禁用:

btnMyButton.enabled = NO; // disable my button
btnMyButton.enabled = YES; // enable my button