UIAlertview中的UITextView无法在iOS 4.x中运行 [英] UITextView in UIAlertview not working in iOS 4.x

查看:55
本文介绍了UIAlertview中的UITextView无法在iOS 4.x中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的医疗应用程序中,我有一项新功能,允许用户将PDF和其他资源下载到Documents文件夹以供离线查看。该应用程序支持iOS 4.1+和iOS 5.用户在警报视图中输入下载文件的名称。对于iOS 5,现在可以轻松地在警报中放置文本字段。对于iOS 4.x中的类似外观,此代码通常运行良好:

In my medical app I have a new feature that allows the user to download PDF's and other resources to the Documents folder for offline viewing. The app supports iOS 4.1+ and iOS 5. The user enters a name for the downloaded file in an alert view. For iOS 5, placing a text field in an alert is now easy. For a similar look and feel in iOS 4.x, this code generally works well:

        alertNameEntryOld = [[UIAlertView alloc] init];
        [alertNameEntryOld setDelegate:self];
        [alertNameEntryOld setTitle:@"Enter new file name:"];
        [alertNameEntryOld setMessage:@" "];
        [alertNameEntryOld addButtonWithTitle:@"Cancel"];
        [alertNameEntryOld addButtonWithTitle:@"Continue"];

        //Check current device orientation.
        UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

        //Place text field position appropriate to device position.
        if (interfaceOrientation == UIInterfaceOrientationPortrait)
            alertTextFieldOld = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
        if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
            alertTextFieldOld = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
            alertTextFieldOld = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 30.0, 245.0, 25.0)];
        if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
            alertTextFieldOld = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 30.0, 245.0, 25.0)];

        [alertTextFieldOld setBackgroundColor:[UIColor whiteColor]];

        //Auto-capitalize first letter with shift key enabled.
        [alertTextFieldOld setAutocapitalizationType:UITextAutocapitalizationTypeSentences];

        [alertNameEntryOld addSubview:alertTextFieldOld];
        [alertNameEntryOld show];
        [alertTextFieldOld release];

我的挫败感来自这个代码适用于iOS 4.1,4.2和4.3的完美状态iPhone,以及iPad上的iOS 4.1。但是,如果在iOS 4.2或4.3的iPad中运行它,相同的代码会创建一个警报视图,文本字段丢失。虽然我的应用程序适用于iPhone,但我当然不希望运行它的iPad用户遇到此错误。似乎iOS软件中可能存在错误。任何修复或替代的想法将非常感激。提前致谢。

My frustration derives from the fact that this code works perfectly well for iOS 4.1, 4.2, and 4.3 on iPhone, as well as iOS 4.1 on iPad. However, if run it in iPad with iOS 4.2 or 4.3, the same code creates an alert view with the text field simply missing. Though my app is for iPhone, I certainly do not want iPad users running it to encounter this error. It seems that there may be a bug in the iOS software. Any thoughts for a fix or alternative would be much appreciated. Thanks in advance.

推荐答案

试试这样:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter new file name:" message:@" " delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:@"Cancel", nil];
UITextView *mTextView = [[UITextView alloc] init];
[mTextView setFrame:CGRectMake(20.0, 30.0, 245.0, 25.0)];
[alert addSubview:mTextView];
[mTextView release];
[alert show];
[alert release];

这篇关于UIAlertview中的UITextView无法在iOS 4.x中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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