4

我在UIActionSheet中展示了一個截取器,非常簡單直到iOS 8。現在,他們似乎已經打破了最新更新的能力。它從來沒有得到過支持,並且這種做法一直在文檔中受挫。iOS 8在UIActionSheet中破解了UIPickerView

據推測,整個UIActionSheet功能已被棄用,並且將不會繼續支持。該文檔說,使用UIAlertController代替。

我試過切換到UIAlertController,實際上發現我最初的預期是比我原來提出的更好的解決方案。

我的原代碼:

// Ask user for project to associate the new issue with a project 
     UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Select Project", @"Title for Action Sheet") 
                  delegate:self 
               cancelButtonTitle:klocalized_CancelButtonTitle 
              destructiveButtonTitle:nil 
               otherButtonTitles:klocalized_SelectButtonTitle ,nil]; 

     [menu addSubview:self.projectPicker]; 
     [menu showFromTabBar:self.tabBarController.tabBar]; 
     [menu setBounds:CGRectMake(0, 0, 320, 700)]; 

在iOS的7

我的新代碼工作的罰款。看起來更好,但由於某種原因,我無法獲得UITextField尊重我的inputView屬性的設置。它顯示我的文本字段與標準鍵盤,否則這將是一個可以接受的選擇,甚至比原來在我看來更好。

新建,正在進行的工作爲iOS 8:

// is iOS 8, ActionSheet, newly deprecated, will not allow subviews. Use UIAlertController instead 
     NSString *title = NSLocalizedString(@"Select Project", @"Title for Action Sheet"); 
     UIAlertController *projectSelector = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; 
     [projectSelector addAction:[UIAlertAction actionWithTitle:klocalized_CancelButtonTitle style:UIAlertActionStyleCancel handler:nil]]; 
     [projectSelector addAction:[UIAlertAction actionWithTitle:klocalized_SelectButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      // Do my button action stuff here 

     }]]; 

     [projectSelector addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
      // projectField is lazily created property. 
      //My picker is set as its inputView but standard keyboard is always presented instead. 
      textField = self.projectField; 
     }]; 

     [self presentViewController:projectSelector animated:YES completion:^{ 
      // Do my final work here 

     }]; 

誰能告訴我爲什麼發生這種情況?是inputViewUITextfield財產在新的UIAlertController視圖上無法使用?有沒有人以這種方式使用UIPickerView

我沒有包含我的代碼projectFieldprojectPicker屬性,但我已經過測試和檢查。他們確實創建有效的對象。選擇器由我提交的VC保留,並且文本字段很弱,我假設我擁有AlertViewController。我試圖保留它,但沒有效果。

我確實收到UITextField委託來自文本字段的調用,所以我知道它是我創建的對象。當我清楚地將pickerView設置爲inputView時,我可以想象沒有標準鍵盤顯示的原因。在截圖

查看結果視圖:

UIAlertController with UITextField

回答

3

敲我的頭在桌子一段時間後,我找到了解決辦法,好了,我的意思是,我發現啞的錯誤,我做。

我正在向後做textField配置。當我設置給定的文本字段的屬性時,我認爲意圖是通過textField參數我的文本字段。

只需更改爲

// is iOS 8, ActionSheet, newly deprecated, will not allow subviews. Use UIAlertController instead 
     NSString *title = NSLocalizedString(@"Select Project", @"Title for Action Sheet"); 
     UIAlertController *projectSelector = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; 
     [projectSelector addAction:[UIAlertAction actionWithTitle:klocalized_CancelButtonTitle style:UIAlertActionStyleCancel handler:nil]]; 
     [projectSelector addAction:[UIAlertAction actionWithTitle:klocalized_SelectButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     }]]; 

     [projectSelector addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
      //Set the properties of the textField provided. DO NOT CREATE YOUR OWN. 
      [textField setPlaceholder:NSLocalizedString(@"Make Selection", @"PlaceHolder for project field when awaiting picker choice")]; 
      [textField setInputView:self.projectPicker]; 
      [textField setDelegate:self]; 
      self.projectField = textField; 
     }]; 

     [self presentViewController:projectSelector animated:YES completion:^{ 

     }]; 
相關問題