Ios 如何从UITableViewCell的UIContextualAction显示popover UIAlertController?

Ios 如何从UITableViewCell的UIContextualAction显示popover UIAlertController?,ios,swift,uitableview,uicontextualaction,Ios,Swift,Uitableview,Uicontextualaction,我想在UITableViewCell中的UIContextualAction“按钮”上演示UIAlertController。我的问题是如何为特定的选定操作设置sourceRect?我认为这是可能的,iOS邮件应用程序允许你在手机上向左滑动时选择更多选项 设置操作时,它有一个视图参数。使用该选项设置操作表 override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt inde

我想在UITableViewCell中的UIContextualAction“按钮”上演示UIAlertController。我的问题是如何为特定的选定操作设置sourceRect?我认为这是可能的,iOS邮件应用程序允许你在手机上向左滑动时选择更多选项

设置操作时,它有一个视图参数。使用该选项设置操作表

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let act1 = UIContextualAction(style: .normal, title: "Bar") { (action, view, completion) in
        completion(false)
    }

    let act2 = UIContextualAction(style: .normal, title: "Foo") { (action, view, completion) in
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        alert.addAction(UIAlertAction(title: "Option 1", style: .default) { (action) in
            completion(true)
        })
        alert.addAction(UIAlertAction(title: "Option 2", style: .default) { (action) in
            completion(false)
        })

        // This sets up the alert to show next to the button
        alert.popoverPresentationController?.sourceView = view
        alert.popoverPresentationController?.sourceRect = view.bounds

        self.present(alert, animated: true, completion: nil)
    }

    return UISwipeActionsConfiguration(actions: [act1, act2])
}

当然,这只适用于iPad,因为在iPhone上,警报将从屏幕底部显示。

设置操作时,它有一个视图参数。使用该选项设置操作表

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let act1 = UIContextualAction(style: .normal, title: "Bar") { (action, view, completion) in
        completion(false)
    }

    let act2 = UIContextualAction(style: .normal, title: "Foo") { (action, view, completion) in
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        alert.addAction(UIAlertAction(title: "Option 1", style: .default) { (action) in
            completion(true)
        })
        alert.addAction(UIAlertAction(title: "Option 2", style: .default) { (action) in
            completion(false)
        })

        // This sets up the alert to show next to the button
        alert.popoverPresentationController?.sourceView = view
        alert.popoverPresentationController?.sourceRect = view.bounds

        self.present(alert, animated: true, completion: nil)
    }

    return UISwipeActionsConfiguration(actions: [act1, act2])
}
当然,这只适用于iPad,因为在iPhone上,警报将从屏幕底部显示