Look out my below code.I am trying to addthe text field with uialertviewcontroller.Now when there is no input in my both text field i need to disable the both action button.How to do that ??
Please make some possible solutions.Thanks !!
Disable the buttons initially and then once you have something in your text field re-enable them.
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"Info"
message:@"You are using UIAlertController with Actionsheet and text fields"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"Resolving UIAlert Action for tapping OK Button");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"Resolving UIAlertActionController for tapping cancel button");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[ok setEnabled:false];
[cancel setEnabled:false];
[alert addAction:ok];
[alert addAction:cancel];
For adding the selector to the text field and then handling it:
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"iCloud ID";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
[textField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
}];
- (void)textDidChange:(UITextField *)textField {
if (textField.text.length > 0) {
// enable the buttons
}
}
For handling textfield delegates you can go through the following posts:
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