首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从UITableViewCell的UIAlertController中显示弹出UIContextualAction?

如何从UITableViewCell的UIAlertController中显示弹出UIContextualAction?
EN

Stack Overflow用户
提问于 2018-10-22 18:02:00
回答 1查看 853关注 0票数 0

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-22 18:30:54

设置操作时,它有一个view参数。使用它来设置操作表。

代码语言:javascript
复制
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上,警报将从屏幕底部显示。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52935197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档