UIAlertView在iOS 8.3 for iPad上解散后弹出键盘 [英] Keyboard pops up after UIAlertView is dismissed on iOS 8.3 for iPad

查看:126
本文介绍了UIAlertView在iOS 8.3 for iPad上解散后弹出键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新的iOS 8.3版本,我们的应用程序开始出现奇怪的行为。

With the latest iOS 8.3 release, our app starts to have a weird behavior.

完成文本字段编辑后,用户可以单击关闭按钮 UIAlertView中。当用户在警报视图中单击 discard 时,将取消警报视图和当前视图。但不知何故键盘在视图消失后出现,这对用户来说非常烦人。

After finishing textfield editing, the user can click the close button which brings up an UIAlertView. When the user clicks discard in the alertview, alertview and current view are dismissed. But somehow the keyboard shows up after the view is gone which is quite annoying to users.

经过一些调试后,似乎键盘显示的是最后一个文本字段用户在关闭视图之前已访问过。我在许多地方为当前视图尝试了各种方法 endEditing (在显示 UIAlertView 之后,点击了 UIAlertView ;我甚至将焦点设置为视图的另一个UI元素。它没有解决问题。

After some debugging, it seems that the keyboard is shown for the last textfield that the user has accessed before closing the view. I tried various ways to endEditing for the current view in many places (before showing UIAlertView, after clicking a button in the UIAlertView; I even set the focus to another UI element of the view). It didn't solve the problem.

但对于这个特殊问题,我不确定这是一个常见问题还是我们需要解决的问题。一切都在iOS 8.3之前完美运行。

But for this particular issue, I'm not sure if it's a common issue or something we need to fix. Everything works perfectly before iOS 8.3.

我们知道iOS 8已弃用 UIAlertView 。我们开始迁移到 UIAlertController 。但如果有任何解决方法,我们很乐意听到。

We understand that UIAlertView is deprecated for iOS 8. We're starting to migrate to UIAlertController. But if there's any workaround, we'd love to hear.

这是一些代码片段。

- (IBAction)closeTapped:(UIButton *)sender
{
    // try to resign first responder
    // [self.tfName resignFirstResponder];
    // [self.tfPosition resignFirstResponder];
    [self.view endEditing:YES];

    if(self.orderDetails.isOpen && self.orderItemChanged)
    {
        UIAlertView* saveAlert = [[UIAlertView alloc] initWithTitle:@"Unsaved Changes"
                                                            message:@"Your changes have not been saved. Discard changes?"
                                                           delegate:self
                                                  cancelButtonTitle:@"Cancel"
                                                  otherButtonTitles:@"Save", @"Discard", nil];
        [saveAlert show];
    }
    else
    {
        [self close];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch(buttonIndex)
    {
        case 1: // Save
        {
            [self save];
            break;
        }
        case 2: // Discard
        {
            [self close];
            break;
        }
    }
}

- (void)close
{   
    [self.delegate dismissEditOrderItemVC];
}


推荐答案

如果您的部署目标是iOS 8+,尝试 UIAlertController

If your deployment target is iOS 8+, try UIAlertController.

这是 UIAlertView :当文本字段或文本视图撤消第一响应者时,延迟显示警报视图的调用。

Here's a quick fix for UIAlertView: delay the invocation of showing the alert view when your text field or text view resigns first responder.

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

这篇关于UIAlertView在iOS 8.3 for iPad上解散后弹出键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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