iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了UIAlertView Vs UIAlertController – iOS 8中没有键盘大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个旧的 Xcode项目,针对iOS 6及更高版本.我最近在Xcode 6中打开了它,并在iOS 8的iPhone 6模拟器中运行.当我尝试这个动作
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];

我得到一个弹出窗口,但当我点击文本字段,没有键盘出现.我googled和阅读,我需要使用UIAlertController代替.因为我需要支持iOS 6,7版本,所以我改变了我的代码.

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];

    }

再次,如果我尝试相同的动作,不显示键盘.

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

解决方法

我测试过,如果iOS8检测到硬件键盘,那么它不会打开键盘.你可能正在模拟器中测试,所以它不是显示任何键盘

按“Command”“k”,你应该可以看到键盘.

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

希望这可以帮助

大佬总结

以上是大佬教程为你收集整理的UIAlertView Vs UIAlertController – iOS 8中没有键盘全部内容,希望文章能够帮你解决UIAlertView Vs UIAlertController – iOS 8中没有键盘所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: