【发布时间】:2012-03-08 03:32:49
【问题描述】:
在我的医疗应用程序中,我有一个新功能,允许用户将 PDF 和其他资源下载到 Documents 文件夹以供离线查看。该应用程序支持 iOS 4.1+ 和 iOS 5。用户在警报视图中输入下载文件的名称。对于 iOS 5,在警报中放置文本字段现在很容易。对于 iOS 4.x 中类似的外观和感觉,此代码通常运行良好:
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];
我的挫败感源于此代码在 iPhone 上的 iOS 4.1、4.2 和 4.3 以及 iPad 上的 iOS 4.1 上运行良好。但是,如果在装有 iOS 4.2 或 4.3 的 iPad 上运行它,相同的代码会创建一个警报视图,而文本字段只是丢失了。虽然我的应用程序适用于 iPhone,但我当然不希望 iPad 用户在运行它时遇到此错误。似乎iOS软件中可能存在错误。任何关于修复或替代的想法将不胜感激。提前致谢。
【问题讨论】:
标签: iphone ios4 uitextfield uialertview