2014-09-03 46 views
2

運行時異常即將到來。運行時異常來時,當我顯示<strong>UIAlertController(ActionSheet)</strong>在<strong>iOS8上beta5的+ Xcode6</strong>顯示UIAlertController(actionsheet)iOS8上

此錯誤只發生在iPad設備。

我在使用UIAlertController時出現波紋異常。

*終止應用程序由於未捕獲的異常 'NSGenericException',原因: ':應該有一個非零sourceView或barButtonItem設置 呈現發生之前UIPopoverPresentationController ( 0x15794370> < _UIAlertControllerActionSheetRegularPresentationController)'。

我顯示ActionSheet代碼如下

 // Cancel Button 
     UIAlertAction *actionCancel = [UIAlertAction 
               actionWithTitle:NSLocalizedString(@"IDS_LABEL_CANCEL", nil) 
               style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 
                // cancel 
                //action handler 
                [self actionHandler:nil withTag:0 withButtonIndex:0]; 
               }]; 

     // print button 
     UIAlertAction *actionPrint = [UIAlertAction 
                 actionWithTitle:NSLocalizedString(@"IDS_LABEL_PRINT", nil) 
                 style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

                  //action handler 
                  [self actionHandler:nil withTag:kAttachmentActionSheetTag withButtonIndex:0];   
              }]; 

    // Create action sheet 
    UIAlertController *alertController = [UIAlertController 
                 alertControllerWithTitle:nil message:nil 
                 preferredStyle:UIAlertControllerStyleActionSheet]; 

[alertController addAction:actionCancel]; 
[alertController addAction:actionPrint]; 

    // show aciton sheet 
    [self presentViewController:alertController animated:YES 
           completion:nil] ; 

回答

5

在iPad上的警報將顯示爲使用新UIPopoverPresentationController一酥料餅,它要求你使用指定酥料餅的呈現錨點下列三個性質中的一種:

爲了指定的錨點,您將需要獲得對UIAlertController的UIPopoverPresentationController參考並設置屬性之一,如下所示:

alertController.popoverPresentationController.sourceView = parentView; 
+0

三江源mmcomb。你剛剛救了我。 – Sabareesh 2014-09-03 10:02:59

+0

如果你沒有'barButtonItem',你不需要'sourceView'和'sourceRect'嗎?在文檔中討論'sourceRect':「將此屬性與sourceView屬性結合使用以指定彈出窗口的錨點位置」。 – 2015-04-29 15:01:32

相關問題