我们在 iOS 8.3 上观察到关于键盘将显示和隐藏通知的异常行为。
viewcontroler(监听键盘通知)有一个文本文件,点击提交按钮后,该方法首先从文本字段中退出第一响应者,并显示警告以通知警告。一切正常,它会关闭键盘并按预期显示警报。(也调用 UIKeyboardWillHideNotification 方法)。
但是,在 8.3 上,在 Alertview 委托上点击 OK/Cancel 后,它会关闭警报并分别调用 UIKeyboardWillShowNotification 和 UIKeyboardWillHideNotification,尽管它不应该被调用!这是出乎意料的,因为键盘在显示警报之前就已经关闭了!
这是我们正在尝试的代码片段:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
- (IBAction)ShowAlert:(id)sender {
[self.TxtField resignFirstResponder];
//This woudln't make any diff either :(
[self.view endEditing:YES];
[self ShowAlertForTest];
}
-(void)ShowAlertForTest{
UIAlertView *theAlertView= [[UIAlertView alloc]initWithTitle:@"Title"
message:@"msg"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Yes", nil];
[theAlertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"buttonIndex = %ld",buttonIndex);
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSLog(@"keyboardWillShow");
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
NSLog(@"keyboardWillHide");
}
这种行为会在我们的应用程序中引起问题,当从先前的 alertview'd 委托触发级联警报时 - 在不需要的情况下启动键盘。
非常感谢任何帮助/建议!