@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
样式。不知道为什么有人可以帮我吗?
谢谢。
最佳答案
在致电show之后,这个丑陋的骇客为我工作了:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// HACKHACK: This is to make the keyboard appear in iOS8
UITextRange* textRange = self.textField.selectedTextRange;
[self.textField selectAll:self];
[UIMenuController sharedMenuController].menuVisible = NO;
self.textField.selectedTextRange = textRange;
});
遇到相同的问题,花了数小时摆弄UIAlertController,这是“正确的”解决方案,但不幸的是在其他地方有几个问题(例如,从弹出窗口显示时出现问题),并且不适用于iOS7。
这绝对是iOS8中的错误。我希望苹果尽快解决此问题。不幸的是,即使使用为iOS7编译的较旧的二进制文件,它也无法达到收支平衡。
关于ios - UIAlertView的文本字段在iOS8中不显示键盘,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25563108/