显示UIAlertController(actionsheet)iOS8时出现的运行时异常 [英] Runtime Exception coming when show UIAlertController(actionsheet) iOS8

查看:298
本文介绍了显示UIAlertController(actionsheet)iOS8时出现的运行时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时异常即将到来。

此Bug仅在 iPad 设备中发生。

This Bug is only happening in iPad Devices.

我在使用UIAlertController时遇到了以下异常。

I'm getting bellow exception when using the UIAlertController.


* 由于未捕获的异常'NSGenericException'终止应用程序,原因:'UIPopoverPresentationController
(< _UIAlertControllerActionSheetRegularPresentationController:
0x15794370>)应该有一个非零的sourceView或barButtonItem设置为
在演示发生之前。'

* Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x15794370>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'

我的代码显示ActionSheet如下

My Code for display ActionSheet as follows



     // 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 ,它要求您指定一个锚点使用以下三个属性之一呈现popover:

On iPad the alert will be displayed as a popover using the new UIPopoverPresentationController, it requires that you specify an anchor point for the presentation of the popover using one of the three following properties:

  • barButtonItem
  • sourceView
  • sourceRect

为了指定锚点,您需要获取对UIAlertController的UIPopoverPresentationController的引用,并设置其中一个属性,如下所示:

In order to specify the anchor point you will need to obtain a reference to the UIAlertController's UIPopoverPresentationController and set one of the properties as follows:

alertController.popoverPresentationController.sourceView = parentView;

这篇关于显示UIAlertController(actionsheet)iOS8时出现的运行时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆