Reputation: 327
I'm trying to make a login dialog in UIAlertController
.
Here is my code:
+ (void)authorizationDialogShow
{
__block UITextField *loginTextField;
__block UITextField *passwordTextField;
UIAlertController *authorizationAlert = [UIAlertController alertControllerWithTitle:@"Authorization"
message:@"Enter login and password."
preferredStyle:UIAlertControllerStyleAlert];
[authorizationAlert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
loginTextField = textField;
loginTextField.placeholder = @"Login";
}];
[authorizationAlert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
passwordTextField = textField;
passwordTextField.placeholder = @"Password";
passwordTextField.secureTextEntry = YES;
}];
[authorizationAlert addAction:[UIAlertAction actionWithTitle:@"Login"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
NSString *login = loginTextField.text;
NSString *password = passwordTextField.text;
[GitAuthorization startAuthorizationWithLogin:login password:password];
}]];
[authorizationAlert addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"End editing");
[authorizationAlert.view endEditing:YES];
[loginTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}]];
[authorizationAlert show];
}
The problem is in cancel UIAlertAction. When I pressed this action, the keyboard dismissed with some delay. Not at the same time as UIAlertController
. What's the problem?
I'm using pod FFGlobalAlertController
. Here some example of this.
Upvotes: 1
Views: 525
Reputation: 11
I have the same issue using UIAlertController
.
My solution is to add a category on UIAlertController
and call [self.view endEditing:YES]
on viewWillDisappear
. Import the category in prefix.pch if it's used widely.
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.view endEditing:YES];
}
Thank for the answer from micap. See link below for detail: iOS 8 Keyboard Dismissed delay after modal view controller is dismissed
Upvotes: 1