2012-03-08 68 views
1

在我的醫療應用程序中,我有一項新功能,允許用戶將PDF和其他資源下載到Documents文件夾以供離線查看。該應用程序支持iOS 4.1+和iOS 5.用戶在警報視圖中輸入下載文件的名稱。對於iOS 5,將文本字段放入警報現在很容易。對於類似的外觀和感覺在iOS的4.x中,該代碼通常會正常工作:UIAlertView中的UITextView無法在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]; 

我無奈從這個代碼可以工作得很好了iOS 4.1的,4.2的事實推導和4.3的iPhone,以及如iPad上的iOS 4.1。但是,如果使用iOS 4.2或4.3在iPad中運行它,則相同的代碼會創建一個警告視圖,並且只會丟失文本字段。儘管我的應用程序適用於iPhone,但我當然不希望iPad用戶運行它來遇到此錯誤。看起來iOS軟件可能存在一個錯誤。任何想法修復或替代將非常感激。提前致謝。

回答

3

嘗試這樣的:

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

感謝您的幫助。根據需要,您的解決方案的工作原理是顯示文本輸入字段。但是,光標漂移不見。我繼續尋找使用UITextField而不是UITextView的解決方案,並最終找到了可以使用更多代碼的解決方案:http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html – user183804 2012-03-10 16:57:17

相關問題