UIAlertView与UIAlertController一样 - iOS 8中没有键盘 [英] UIAlertView Vs UIAlertController - no keyboard in iOS 8

查看:153
本文介绍了UIAlertView与UIAlertController一样 - iOS 8中没有键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对iOS 6及更高版本的旧Xcode项目。我最近在Xcode 6中打开它并在iOS 8的iPhone 6模拟器中运行。当我尝试此操作时

I have a old Xcode project that is targeted for iOS 6 and higher. I recently opened it up in Xcode 6 and ran in iPhone 6 simulator for iOS 8. When I tried this action

UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Folder Name"
                                                     message:@"Keep it short and sweet"
                                                    delegate:self
                                           cancelButtonTitle:@"Cancel"
                                           otherButtonTitles:@"OK", nil];

    dialog.alertViewStyle = UIAlertViewStylePlainTextInput;
    dialog.tag = 400;
    [dialog show];

我得到一个弹出窗口但是当我点击文本字段时,没有键盘出现。我用Google搜索并读取我需要使用UIAlertController。因为我需要支持iOS 6,7版本,所以我改变了我的代码。

I get a pop-up window but when I click on the text field, no keyboard comes up. I googled and read that I need to use UIAlertController instead. Since I need to support iOS 6, 7 versions as well so I changed my code like this.

if ([UIAlertController class])
    {
        // use UIAlertController
        UIAlertController *alert= [UIAlertController
                                      alertControllerWithTitle:@"Enter Folder Name"
                                      message:@"Keep it short and sweet"
                                      preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                   handler:^(UIAlertAction * action){
                                                       //Do Some action here
                                                       UITextField *textField = alert.textFields[0];
                                                       NSLog(@"text was %@", textField.text);

                                                   }];
        UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * action) {

                                                           NSLog(@"cancel btn");

                                                           [alert dismissViewControllerAnimated:YES completion:nil];

                                                       }];

        [alert addAction:ok];
        [alert addAction:cancel];

        [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
            textField.placeholder = @"folder name";
            textField.keyboardType = UIKeyboardTypeDefault;
        }];

        [self presentViewController:alert animated:YES completion:nil];

    }
    else
    {
        // use UIAlertView
        UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Folder Name"
                                                         message:@"Keep it short and sweet"
                                                        delegate:self
                                               cancelButtonTitle:@"Cancel"
                                               otherButtonTitles:@"OK", nil];

        dialog.alertViewStyle = UIAlertViewStylePlainTextInput;
        dialog.tag = 400;
        [dialog show];

    }

如果我尝试相同的动作没有键盘会显示。

Again if I try the same action NO keyboard is displayed.

这是Xcode 6模拟器中的错误还是我做错了什么?

Is this a bug in Xcode 6 simulator or I am doing something wrong?

推荐答案

我测试了这个,如果iOS8检测到硬件键盘,而不是打开键盘。正如您可能正在模拟器中进行测试,因此它没有显示任何键盘

I Tested this, if iOS8 detects a hardware keyboard , than it does not open the keypad. As you might be testing in simulator , so it is not Showing any keypad

按Command+k,您应该可以看到键盘。

Press "Command" + "k" and you should be able to see the keypad.

在设备上进行测试时,除非用户已将设备与硬件蓝牙键盘连接,否则您不会遇到此问题,因此这不是您应该担心的问题

When testing on a device you will not face this issue , unless user has connected his device with a hardware Bluetooth keypad , so this is not something you should worry about

希望这有助于

这篇关于UIAlertView与UIAlertController一样 - iOS 8中没有键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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