iosswiftxcodecrashuipopovercontroller

UIPopOverPresentationController crashes on presentationTransitionWillBegin


I am receiving crashes from Apple like this:

enter image description here

The crash report is so bad, as expected for Xcode, that I have to guess where in my code this is coming from.

The crash talks about popover. The only part of my code where I have popover is this `share" stuff, when I have these "delete" and "share" trailing swipe action on a table view that shows files from the documents folder.

 override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    let delete = ... bla bla bla

    let share = UIContextualAction(style: .normal, title: "") {[weak self] (contextualAction, view, boolValue) in
      let oneFile = self?.files![indexPath.section]![indexPath.row]
      
      let activityViewController = UIActivityViewController(
        activityItems: ["Check out these files.", (oneFile?.url)! as URL],
        applicationActivities: nil
      )
      
      activityViewController.popoverPresentationController?.sourceView = self?.view
      self?.present(activityViewController, animated: true, completion: {[weak self] in
        self?.tableView.setEditing(false, animated: true)
      })
    }

    let swipeActions = UISwipeActionsConfiguration(actions: [delete,share])
    swipeActions.performsFirstActionWithFullSwipe = true
    
    return swipeActions
}

Is there anything you guys see here that can be causing the crash?

The reports show this is crashing on the iPad but I test and it is working fine.


Solution

  • You should define both sourceRect and sourceView of the popoverPresentationController.