iPhone 5c中的键盘隐藏/显示问题

时间:2015-12-02 06:29:58

标签: ios objective-c iphone keyboard uikeyboard

从过去的几天开始,我面临一个奇怪的keyboard问题,该问题仅发生在iPhone 5c

我在objective-C

中使用Xcode-6.4进行开发

我的环境目标是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我正在撰写这段代码。确保我为每个textField使用-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];
 }
}

现在,当我从服务器获得成功/失败响应时,我正在执行此操作。这是从服务器获得响应后运行的块:

-(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中检查了它。一切正常。

如果有人知道,请协助。

2 个答案:

答案 0 :(得分:0)

您正在显示警报,同时您也在执行popToRootViewController。可能这会引起问题。

  1. 显示提醒。
  2. 处理警报视图方法。
  3. 在警告视图的方法中写[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]; 
         }
    }];
    
  4. 希望这会对你有所帮助。

答案 1 :(得分:0)

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

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

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

JLabel#setIcon(...)

有关详细信息,请参阅this SO answer