【发布时间】:2012-10-13 13:42:52
【问题描述】:
在 viewDidLoad 中,我检查两个 UITextField 是否具有有效输入(文本长度 > 0),然后设置 UIButton 的 enabled 属性。使用调试器我发现
self.loginButton.enabled = YES;
被执行,但是当我用
打印布尔值时print self.loginButton.enabled
我在执行语句之前得到 NO(这没关系),但在执行语句之后也得到 NO。我还多次检查了 self 的 UIButton 属性是否使用 IBOutlet 连接到我的故事板中的 UIButton,就是这种情况。我还可以使用控制台打印 titleLabel 的文本。当我点击其中一个 UITextFields 并更改文本时
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
正在被调用,我将在那里再次检查文本。这里
self.loginButton.enabled = YES;
似乎工作正常。使用 iOS 5 时我没有任何问题,但我在此问题的文档中没有发现 iOS 6 的任何相关更改。
有什么想法吗?
编辑:问题有所不同。我在那个 UIViewController 中也有一个 UITableView,并且 tableView 比预期的要大(然后在 Storyboard 中设置更大)(直到知道我不知道为什么)并且似乎覆盖了 UIButton。在执行前更改 UIButton 或 UITableView 的框架
self.loginButton.enabled = YES;
有效。设置启用属性时可能会有延迟,因为打印布尔值仍然返回 NO。
NSLog(@"%i",self.loginButton.isEnabled);
self.loginButton.enabled = YES;
NSLog(@"%i",self.loginButton.isEnabled);
2012-10-13 16:11:43.460 [1524:c07] 1
2012-10-13 16:11:43.462 [1524:c07] 1
【问题讨论】:
标签: ios uibutton ios6 uicontrol