1

我正在尝试在UIAlertController. 这是我的代码:

+ (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];
}

问题在于取消 UIAlertAction。当我按下此操作时,键盘会延迟一段时间消失。不是同时UIAlertController。有什么问题?

我正在使用 pod FFGlobalAlertController这里有一些例子

4

1 回答 1

1

我使用UIAlertController. 我的解决方案是添加一个类别UIAlertController并调用[self.view endEditing:YES]. 如果广泛使用,请在prefix.pchviewWillDisappear中导入类别。

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
}

感谢 micap 的回答。有关详细信息,请参见下面的链接: iOS 8 Keyboard Dismissed delay after modal view controller is dismissed

于 2016-06-09T18:26:50.810 回答