问题描述
我很困惑为什么此代码无法正常工作.我有一个要在用户未登录时禁用的登录按钮.
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)
我可以使用同一屏幕上的其他两个按钮来执行此操作,因此我知道代码是正确的.我不会抛出任何错误,因此我认为该对象存在.对myBtn的引用也会在XCode中更改颜色,因此它似乎是有效的引用.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!