以编程方式禁用 UIButton [英] Disable UIButton programmatically

查看:22
本文介绍了以编程方式禁用 UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑为什么这段代码不起作用.我有一个登录按钮,我想在用户未登录时禁用它.

I'm stumped at why this code isn't working. I have a login button that I want to disable when the user isn't logged in.

我的 .h 文件中有一个 UIButton,如下所示:

I have a UIButton delared in my .h file like so:

   IBOutlet UIButton *myBtn;

我已经在 Interface Builder 中为这个按钮设置了一个引用出口.

I've set up a referencing outlet in Interface Builder to this button.

在我的 .m 文件中,我尝试过:

In my .m file, I've tried:

[myBtn setEnabled: NO];

myBtn.enabled = NO;

但是这些都没有禁用我所在的条件语句中的按钮.(我想在用户成功登录时禁用登录按钮)

But neither of these disable the button in the conditional statement I'm in. (I want to disable the login button when the user successfully logs in)

我可以在同一屏幕上使用另外两个按钮来执行此操作,所以我知道代码是正确的.我没有抛出任何错误,所以我认为该对象存在.在 XCode 中对 myBtn 的引用也会改变颜色,因此它似乎是一个有效的引用.

I'm able to do this with two other buttons on the same screen, so I know the code is correct. I don't throw any errors, so I think the object exists. The references to myBtn change color in XCode, too, so it appears to be a valid reference.

我一定错过了什么.我在这里做错了什么?(我是一名 Windows 开发人员,在 Objective-C 方面相对较新)

I must be missing something. What am I doing wrong here? (I'm a Windows developer, relatively new at Objective-C)

推荐答案

我觉得没问题.您在合成按钮吗?试试

It seems ok to me. Are you synthesizing the button? Try

self.myBtn.enabled = NO;

这篇关于以编程方式禁用 UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆