• UIAlertController和UIActivityViewController在ipad中的兼容性问题


    1、报错提示

    • 1.1 UIAlertController

      • Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x1048f5600>) of style UIAlertControllerStyleActionSheet from
    • 1.2 UIActivityViewController

      • Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIActivityViewController (<UIActivityViewController: 0x103840000>). In its current trait environment, the modalPresentationStyle of a UIActivityViewController with this style is UIModalPresentationPopover.

    2、解决办法

    • 问题原因:这两个crash原因都是因为在ipad上进行UIAlertController和UIActivityViewController的使用的时候,都需要瞄点。
    • 2.1 UIAlertController

    // 兼容ipad
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
      alert.popoverPresentationController.sourceView = sourceView;
      alert.popoverPresentationController.sourceRect = sourceView.bounds;
      alert.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
    }
    
    • 2.1 UIActivityViewController

    // 兼容ipad
    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        vc.popoverPresentationController.sourceView = self.view;
        vc.popoverPresentationController.sourceRect = CGRectMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0, 1.0, 1.0);
        vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
    }
    
    • 提示:其中vc就是对应的UIAlertController、UIActivityViewController的实例对象。
  • 相关阅读:
    POJ 3687 Labeling Balls <<拓扑排序
    FATFS 初学之 f_mount
    STM8 低功耗时钟管理
    还记得 C中带参宏的 "#"号吗?
    8.9并发编程(一)
    8.8网络编程(三)
    8.7网络编程(二)
    8.6网络编程(一)
    7.30反射、元类及项目生命周期
    7.29多态
  • 原文地址:https://www.cnblogs.com/CH520/p/15691367.html
Copyright © 2020-2023  润新知