我正在使用objective-c寫入關於UIAlertControllerStyleActionSheet
的UIAlertcontroller
。iOS popover顯示兩次會崩潰
我想在iPhone上顯示警報表,並在iPad上顯示popoverPresentationController
。
首先,我已經設置了UIPopoverPresentationControllerDelegate
委託。
當我點擊我的按鈕時,彈出窗口顯示正確。
但我點擊屏幕關閉彈出。它會顯示下面的警告。
[警告] < _UIPopoverBackgroundVisualEffectView 0x14be52ef0>被要求爲其不透明度設置動畫。這將導致效果顯示中斷,直到不透明度返回到1.
現在當我單擊按鈕時再次顯示彈出視圖。
它會在日誌下面顯示崩潰。
由於未捕獲的異常「NSGenericException」而終止應用程序,原因:'您的應用程序提供了樣式爲UIAlertControllerStyleActionSheet的UIAlertController()。具有此樣式的UIAlertController的modalPresentationStyle是UIModalPresentationPopover。您必須通過警報控制器的popoverPresentationController爲此彈出窗口提供位置信息。您必須提供sourceView和sourceRect或barButtonItem。如果在提供警報控制器時未知此信息,則可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供該信息。 ***第一擲調用堆棧: (0x18d9a41c0 0x18c3dc55c 0x19418a8b0 0x193ac60a8 0x193ac3df4 0x193a08d0c 0x1939faac0 0x19376a22c 0x18d9517dc 0x18d94f40c 0x18d94f89c 0x18d87e048 0x18f2ff198 0x1937e2b50 0x1937dd888 0x10011198c 0x18c8605b8) 的libC++ abi.dylib:與類型的未捕獲的異常終止NSException
有誰知道如何解決這個問題?
我的代碼如下:
@interface ViewController() <...UITextViewDelegate,UITextFieldDelegate...> {
UIAlertController *alertTypeAlertController;
UIAlertAction *alertType1Action;
UIAlertAction *alertType2Action;
UIPopoverPresentationController *popPresenter;
}
- (void)viewDidLoad {
[super viewDidLoad];
alertTypeAlertController = [UIAlertController
alertControllerWithTitle:@"selecte one:"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alertType1Action = [UIAlertAction
actionWithTitle:@"Type1"
style:UIAlertActionStyleDefault
handler:nil];
alertType2Action = [UIAlertAction
actionWithTitle:@"Type2"
style:UIAlertActionStyleDefault
handler:nil];
[alertTypeAlertController addAction: alertType1Action];
[alertTypeAlertController addAction: alertType2Action];
// for ipad
popPresenter = [alertTypeAlertController popoverPresentationController];
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popPresenter.delegate = self;
popPresenter.sourceView = self.theTypeBtn;
popPresenter.sourceRect = CGRectMake(230, 22, 10, 10);
....
}
- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
// called when a Popover is dismissed
}
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
// return YES if the Popover should be dismissed
// return NO if the Popover should not be dismissed
return YES;
}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
enter code here
非常感謝你。
我試試「UIPopoverPresentationController * popPresenter」,結果仍然顯示了同樣的錯誤之前添加__weak。:( – dickfala
檢查第二個彈出如果self.presentedViewController是零,正常的應用程序崩潰,如果你試圖呈現2查看控制器 –
我查看第一個點擊按鈕,彈出窗口是零(self.presentedViewController),但是顯示正確,應用程序沒有崩潰,但點擊第二個按鈕,彈出窗口仍然爲零,應用程序崩潰。@@ – dickfala