Last active
August 29, 2015 14:20
-
-
Save D-32/2aaa0b6959e253a3d93a to your computer and use it in GitHub Desktop.
UIAlertController with text field check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" | |
message:nil | |
preferredStyle:UIAlertControllerStyleAlert]; | |
UIAlertAction *cancelAlertAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault | |
handler:^(UIAlertAction * action) {}]; | |
_saveAlertAction = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault | |
handler:^(UIAlertAction * action) { | |
}]; | |
_saveAlertAction.enabled = NO; | |
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { | |
textField.placeholder = @"Enter a title..."; | |
[textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged]; | |
}]; | |
[alert addAction:cancelAlertAction]; | |
[alert addAction:_saveAlertAction]; | |
[self presentViewController:alert animated:YES completion:nil]; | |
// ---------------------- | |
- (void)textChanged:(id)sender | |
{ | |
UITextField *field = sender; | |
_saveAlertAction.enabled = field.text.length > 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment