Sab*_*esh 2 ios8 uialertcontroller
当我在iOS8 Beta5 + Xcode6中显示UIAlertController(ActionSheet)时,运行时异常即将到来.
此Bug仅在iPad设备中发生.
我在使用UIAlertController时遇到了轰鸣声异常.
*由于未捕获的异常'NSGenericException'终止应用程序,原因:'UIPopoverPresentationController(<_UIAlertControllerActionSheetRegularPresentationController:0x15794370>)应该在演示发生之前设置非零的sourceView或barButtonItem.
我的代码显示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] ;
Run Code Online (Sandbox Code Playgroud)
在iPad上,警报将使用新的UIPopoverPresentationController显示为弹出窗口,它要求您使用以下三个属性之一为弹出窗口的表示指定锚点:
为了指定的锚点,您将需要获得参考UIAlertController的UIPopoverPresentationController并设置属性之一,如下所示:
alertController.popoverPresentationController.sourceView = parentView;
Run Code Online (Sandbox Code Playgroud)