我正在尝试在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
不同时。有什么问题?
我正在使用广告FFGlobalAlertController
。 Here some example of this
答案 0 :(得分:1)
我使用UIAlertController
时遇到了同样的问题。
我的解决方案是在UIAlertController
上添加一个类别,并在[self.view endEditing:YES]
上调用viewWillDisappear
。如果广泛使用,请在 prefix.pch 中导入该类别。
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.view endEditing:YES];
}
感谢micap的回答。请参阅以下链接了解详情: iOS 8 Keyboard Dismissed delay after modal view controller is dismissed