【问题标题】:Keyboard Hide/Show issue in iPhone 5ciPhone 5c 中的键盘隐藏/显示问题
【发布时间】:2016-03-06 07:30:10
【问题描述】:

从过去几天开始,我遇到了一个奇怪的 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 我正在编写这段代码。确保我对每个文本字段都使用-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 中检查了它。一切正常。

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

【问题讨论】:

    标签: ios objective-c iphone keyboard uikeyboard


    【解决方案1】:

    你在显示警报的同时你也在做 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]; 
           }
      }];
      

    希望这会对你有所帮助。

    【讨论】:

    • 没有变化,,,我所有的文本字段都在表格视图中...会是表格视图率问题
    • 那个 tableview 是在显示 alertview 的同一个 viewcontroller 上?
    【解决方案2】:

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

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

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

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

    详细解答请参考this SO answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 2011-03-08
      • 1970-01-01
      相关资源
      最近更新 更多