当我在iOS8 Beta5 + Xcode6中显示UIAlertController(ActionSheet)时,将出现运行时异常。
此错误仅在iPad设备中发生。
使用UIAlertController时出现波纹管异常。
*由于未捕获的异常'NSGenericException'而终止应用程序,原因:'UIPopoverPresentationController(<_UIAlertControllerActionSheetRegularPresentationController:0x15794370>)在演示之前应设置非null的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] ;
在iPad上,警报将使用新的UIPopoverPresentationController显示为弹出窗口,它要求您使用以下三个属性之一为弹出窗口的显示指定锚点:
为了指定锚点,您将需要获取对UIAlertController的UIPopoverPresentationController的引用,并按如下所示设置属性之一:
alertController.popoverPresentationController.sourceView = parentView;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句