键盘将在显示Alertview或Alertcontroller时自动出现在ios 8.3中 [英] Keyboard will appeared automatically in ios 8.3 while displaying alertview or alertcontroller
问题描述
我已经更新了Xcode 6.3和ios8.3,请检查我的代码.那给我怪异的结果
I have updated Xcode 6.3 and ios8.3 check my code. then it gives me weird result.
这是我的演示应用程序的第一个屏幕.这是一个文本字段.当我在打开的文本字段键盘中键入somethin时.
here is first screen of my demo app. here is one textfield. when I type somethin in textfield keyboard open.
输入完成后.我单击了显示警报按钮.我已经显示了警报,并且将显示以下输出.
after typing completed. I have clicked on show alert button. I have displayed alert and output will be following.
单击取消后. 我已经显示了另一个警报,但是当单击取消"按钮时,奇怪的结果键盘不应该打开.显示另一个警报,键盘将自动出现.
After click on cancel. I have displayed another alert then weird result keyboard should not open but when click on cancel button. display another alert and keyboard will appear automatically.
这是下一个屏幕输出
以下是代码
- (IBAction)MethodShowAlert:(id)sender
{
[tmptxtField resignFirstResponder];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Check Alert textField" message:@"keyboard should not be open" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self showCustomAlertWithTitle:nil];
}
-(void)showCustomAlertWithTitle:(NSString *)title{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Now Check" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alertView show]
}
推荐答案
是的,很奇怪.
但是从iOS 8开始,我建议使用UIAlertController而不是UIAlertView.
But since iOS 8, I suggest to use the UIAlertController instead of UIAlertView.
用以下代码替换您的代码:
Replace your code with this one:
- (IBAction)MethodShowAlert:(id)sender
{
[tmptxtField resignFirstResponder];
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Check Alert textField"
message:@"keyboard should not be open"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self showCustomAlertWithTitle:@"Now Check"];
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
-(void)showCustomAlertWithTitle:(NSString *)title{
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:title
message:nil
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
}
单击按钮后,键盘将不会显示.
The keyboard will not show after the click on the button.
这篇关于键盘将在显示Alertview或Alertcontroller时自动出现在ios 8.3中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!