gpt4 book ai didi

ios - 来自 UIAlertController 的键盘延迟关闭

转载 作者:行者123 更新时间:2023-11-29 12:03:24 28 4
gpt4 key购买 nike

我正在尝试在 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。当我按下这个 Action 时,键盘会延迟关闭。与 UIAlertController 不同时。有什么问题?

我正在使用 pod FFGlobalAlertControllerHere some example of this .

最佳答案

我在使用 UIAlertController 时遇到了同样的问题。我的解决方案是在 UIAlertController 上添加一个类别,并在 viewWillDisappear 上调用 [self.view endEditing:YES]。如果广泛使用,请在 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

关于ios - 来自 UIAlertController 的键盘延迟关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970517/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com