我想在UIAlertController中的UIContextualAction“按钮”上显示一个UITableViewCell。我的问题是如何为特定的选定操作设置sourceRect?我想这是可能的,iOS邮件应用程序允许你在单元格上滑动时选择更多的选项(见图)。

发布于 2018-10-22 18:30:54
设置操作时,它有一个view参数。使用它来设置操作表。
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上,警报将从屏幕底部显示。
https://stackoverflow.com/questions/52935197
复制相似问题