iPhone 5c 中的键盘 Hide/Show 问题

Keyboard Hide/Show issue in iPhone 5c

从过去几天开始,我遇到了一个奇怪的 keyboard 问题,该问题仅在 iPhone 5c 中发生。

我在 Xcode-6.4

中使用 objective-C 进行开发

我的环境目标是ios7

这是我处理的方式 keyboard Notification

 - (void)viewDidAppear:(BOOL)animated{

[super viewDidAppear:animated];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

}

Deregister Notification 我正在写这篇 code.To 请确保我对每个文本字段都使用 -resignFirstResponder

- (void)viewWillDisappear:(BOOL)animated{

[super viewWillDisappear:animated];

[self hideKeyBoard];
[self.view endEditing:YES];

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


- (void)hideKeyBoard{

[kAgeTextField resignFirstResponder];
[kSchoolTextField resignFirstResponder];
}

在提交按钮中,我检查了一些条件,然后我显示了 AlertView

- (IBAction)submitClicked:(id)sender
{
if(validated)
 {    
    [self.view endEditing:YES];
    [self hideKeyBoard];
    [self.view resignFirstResponder]; 

    [self makeApiCall];
 }
}

现在,当我收到来自服务器的 Success/Failure 响应时,我正在做 this.This 是在收到服务器响应后运行的块:

-(void)SuccessfulWithServerInfo:(id)responseInfo
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
dispatch_async(dispatch_get_main_queue(),^{
    [appDelegate hideProgressViewFromView:self.view];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"Thanks for coming" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [self.navigationController popToRootViewControllerAnimated:YES];


});

}

问题 当我收到 alertBox 并按确定时。然后键盘自动打开和关闭。这仅在 iPhone 5C 发生。我在4s,5s,6和6Plus里查过。一切正常。

如果有人知道,请提供帮助。

您在显示警报的同时也在执行 popToRootViewController。可能这会导致问题。

  1. 显示警报。
  2. 处理警报视图方法。
  3. 在alert视图的方法中写[self.navigationController popToRootViewControllerAnimated:YES]。

    [UIAlertView showWithTitle:@"" message:@"Thanks for coming" cancelButtonTitle:@"OK" otherButtonTitles:nil] alertViewStyle:UIAlertViewStyleDefault tapBlock:^(UIAlertView *alertView, NSInteger buttonIndex, NSString *text)
     {
         if(buttonIndex == 1)
         {
             [self.navigationController popToRootViewControllerAnimated:YES]; 
         }
    }];
    

希望对您有所帮助。

经过一些研究,我在 Whosebug 中找到了这个答案。

它们是 ios7 和 ios8 中 AlertView 行为的一些变化。

我使用这段代码来解决我的问题:

[self performSelector:@selector(showAlertView) withObject:nil afterDelay:0.6];

详细答案请参考this SO answer