How do i disable a UIButton until there is text in the UITextField. The code i have doesn't seem to work.
if ([nameTextField.text isEqualToString: @""]) {
[myButton setEnabled:NO];
}
Here's the code from kingthong's blog post, which worked for me:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.saveButton setEnabled:NO];
[[self myTextField] becomeFirstResponder];
[myTextField addTarget:self
action:@selector(textFieldDidChange)
forControlEvents:UIControlEventEditingChanged];
}
- (void)textFieldDidChange
{
if ([self.myTextField.text isEqualToString:@""]) {
[self.saveButton setEnabled:NO];
}
else {
[self.saveButton setEnabled:YES];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With