在iOS8.3上显示Alertviews时,不必要地触发了iOS键盘通知 [英] iOS Keyboard notifications triggered unnecessarily upon showing the alertviews on iOS8.3

查看:164
本文介绍了在iOS8.3上显示Alertviews时,不必要地触发了iOS键盘通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们观察到有关Keyboard willshow&的异常行为.将在iOS 8.3上隐藏通知.

We are observing unusual behaviour with respect to Keyboard willshow & will hide notification on iOS 8.3.

viewcontroler(侦听键盘通知)具有文本文件,单击并单击提交按钮时,该方法首先从文本字段中退出第一响应者,并显示警报以告知警告.一切正常,关闭键盘并按预期显示警报. (也调用UIKeyboardWillHideNotification方法).

The viewcontroler (listenig to keyboard notifications) has a textfiled and upon clicking and upon tapping the submit button, the method first resigns the first responder from textfield, and shows an alert to inform warning. Everything works fine, it dismisses the keyboard and shows up the alert as expected. (calls the UIKeyboardWillHideNotification method too).

但是,在8.3上,在Alertview委托上点击OK/Cancel后,它将关闭警报并调用UIKeyboardWillShowNotification&. UIKeyboardWillHideNotification分别,尽管不应该调用它!这是意料之外的,因为在取消警报之前已经将键盘关闭了!

However, on 8.3, after tapping OK/Cancel on Alertview delegate, it dismisses the alert and it calls up UIKeyboardWillShowNotification & UIKeyboardWillHideNotification respectively, though it was not supposed to be called! This was not expected, as the keyboard was already dismissed before dispalying the alert!

这是我们正在尝试的代码段:

Here is the code snippet, that we are trying:

- (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委托触发了级联警报时-在不需要的情况下打开键盘.

This behaviour is causing issues in our app, when there are cascading alerts triggered from the previous alertview'd delegate - bringing up the keyboard in unneeded situations.

任何帮助/建议都将不胜感激!

Any help /advice is greatly appreciated!

推荐答案

在我们的案例中,键盘是由应用手动隐藏的(例如,当用户点击登录"时,我们会隐藏键盘并调用服务器登录API).失败后,应用程序会显示UIAlertView并显示错误消息.当用户关闭警报时,iOS帖子将/不会隐藏和删除;将/没有显示通知.当然,键盘不会显示和显示.在此序列中被隐藏,因为它已被应用程序隐藏.

In our case the keyboard was hidden manually by the app (e.g. when user taps Log In, we hide keyboard and call the server login API). Upon failure the app presents UIAlertView with an error message. When user closes the alert, iOS posts will/did hide & will/did show notifications. Of course the keyboard is not shown & hidden during this sequence, because it is already hidden by the app.

但是,我们注意到不是手动隐藏键盘,而是让iOS为我们完成此操作,此问题已得到解决.因此,键盘在两种情况下会自动隐藏:

However, we noticed that not hiding keyboard manually, but instead letting iOS to do it for us, fixes the issue. So, the keyboard is hidden automatically in two cases:

  1. 显示UIAlertView
  2. 当视图控制器被释放时

注意:关闭UIAlertView时,键盘会自动显示.

Note: the keyboard is automatically shown when UIAlertView is dismissed.

这篇关于在iOS8.3上显示Alertviews时,不必要地触发了iOS键盘通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆