gpt4 book ai didi

ios - UIAlertView 文本字段在 iOS 8 中不显示键盘

转载 作者:IT王子 更新时间:2023-10-29 08:14:35 25 4
gpt4 key购买 nike

@implementation
UIAlertView *query;
@end

- (void)viewWillAppear:(BOOL)animated {
query = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"New", @"")
message:nil
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
otherButtonTitles:NSLocalizedString(@"OK", @""), nil];
query.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [_query textFieldAtIndex:0];
textField.placeholder = NSLocalizedString(@"Title", @"placeholder text where user enters name for new playlist");
textField.delegate = self;
[_query show];
}

在显示 UIAlertView 之后,键盘也会显示,并且 UITextfield 是焦点(它只适用于 iOS7 之前的版本,但在 iOS8 中不起作用)。我试过 [textfield becomeFirstResponder],但没有用。我创建了新项目并使用上面的 cove,它有效。

我的问题:键盘未以 UIAlertViewStylePlainTextInput 样式显示。

不知道为什么?有人可以帮助我吗?谢谢。

最佳答案

这是对 Chen Lim 的 hack/fix 的轻微改进,将放置在 UIAlertViewDelegate 中:

- (void)didPresentAlertView:(UIAlertView *)alertView {
if (isIOS8) {
// hack alert: fix bug in iOS 8 that prevents text field from appearing
UITextRange *textRange = [[alertView textFieldAtIndex:0] selectedTextRange];
[[alertView textFieldAtIndex:0] selectAll:nil];
[[alertView textFieldAtIndex:0] setSelectedTextRange:textRange];
}
}

(您必须实现 isIOS8 方法、属性或 iVar。)

关于ios - UIAlertView 文本字段在 iOS 8 中不显示键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25563108/

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