2014-09-26 35 views
4

我可以在iOS 7中顯示actionSheet,但無法在iOS 8環境中顯示。有什麼方法可以追蹤?UIActionSheet不顯示在iOS 8中

UIActionSheet *_actionSheet = [[UIActionSheet alloc] initWithTitle:@"Account" 
                   delegate:self 
                 cancelButtonTitle:@"Close" 
               destructiveButtonTitle:@"Log Out" 
                 otherButtonTitles:@"View Account", nil]; 

    [_actionSheet showInView:appDel.window]; 
+1

這是因爲'UIActionSheets'在'iOS8'中不再存在,所以它們已被棄用以支持'UIAlertController'閱讀https://developer.apple.com/Library/ios/documentation/UIKit/Reference /UIAlertController_class/index.html – Popeye 2014-09-26 14:28:41

+2

@Popeye「棄用」並不意味着「消除」,而是「請避免」。它應該仍然工作,雖然 – 2014-10-24 07:40:21

+0

在我的iPhone應用程序,不,它不工作了。使用iOS 9,我的UIActionSheet現在只是使整個屏幕變暗,並且不會出現彈出式菜單。我的修復細節在這裏:http://stackoverflow.com/questions/32824199/action-sheet-problems-in-ios-9/35316029#35316029(嘆息...) – 2016-02-10 13:04:30

回答

3

UIActionSheet在iOS的8

enter image description here

已被棄用要創建和管理的iOS 8張的行動你應該UIAlertControllerStyleActionSheet的preferredStyle使用UIAlertController。

請參閱此example

+1

我也參考這個頁面,但我是獲取「您必須提供sourceView和sourceRect或barButtonItem。如果在顯示警報控制器時未知此信息,則可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供該信息。我指的是其他頁面,但我被扣在按鈕部分。 http://stackoverflow.com/questions/24224916/presenting-a-uialertcontroller-properly-on-an-ipad-using-ios-8 – 2014-09-26 15:06:32

0

這顯然是iOS 8中的一種迴歸。我已經提交了rdar,請也這樣做。

與此同時,您可以使用類別或子類來修復它,檢查視圖是否爲窗口,如果是,則在該窗口中抓取rootViewController的視圖並改爲使用它。它會這樣工作。

0

當iOS 8發佈時,我遇到了操作表問題。您提出的觀點可能是一個問題。您能否以實際的視角而不是窗口顯示它?我會先在那裏做實驗,並且作爲最糟糕的情況,將展示方法包裝爲iOS 7和8特定的東西。我開始使用PSTAlertController來管理我的警報和操作表。它支持UIAlertView,UIActionSheet和U​​IAlertController。它將整理哪一個使用,以及讓你訪問阻止你的按鈕,同時仍支持iOS 7和8.值得一看。

1
UIAlertController * alert= [UIAlertController 
          alertControllerWithTitle:@"Info" 
          message:@"You are using UIAlertController" 
          preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* ok = [UIAlertAction 
        actionWithTitle:@"OK" 
        style:UIAlertActionStyleDefault 
        handler:^(UIAlertAction * action) 
        { 
         [alert dismissViewControllerAnimated:YES completion:nil]; 

        }]; 
UIAlertAction* cancel = [UIAlertAction 
         actionWithTitle:@"Cancel" 
         style:UIAlertActionStyleDefault 
         handler:^(UIAlertAction * action) 
         { 
          [alert dismissViewControllerAnimated:YES completion:nil]; 

         }]; 

[alert addAction:ok]; 
[alert addAction:cancel]; 

[self presentViewController:alert animated:YES completion:nil]; 
0

如果任何人看到這個問題,這個問題實際上是由iOS的8,9引起的顯示你的動作片背後屏幕鍵盤,所以你不能真正看到它。你只會看到屏幕的其餘部分變暗。天才。

簡單的解決辦法是顯示前添加一行代碼你UIActionSheet

[self.view endEditing:true]; 

這駁回了屏幕鍵盤,使您的再次動作優美片可見。