ios - UIContextualAction 显示 UIMenu

标签 ios swift xcode uikit

我注意到,在 Facebook Messenger 中,当有人按下 UIContextualAction 时,它们会显示 UIMenu

我可能错过了一些东西,但我不知道该怎么做。如果有人知道执行此操作的代码,我将不胜感激。

最佳答案

好吧,我不喜欢这种方法,但到目前为止这对我有用。我发现this solution访问 UIButton,然后您可以为其设置菜单。

func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
    for subview in tableView.subviews {
        if NSStringFromClass(type(of: subview)) == "_UITableViewCellSwipeContainerView" {
            for swipeContainerSubview in subview.subviews {
                if NSStringFromClass(type(of: swipeContainerSubview)) == "UISwipeActionPullView" {
                    for case let button as UIButton in swipeContainerSubview.subviews {
                        var menuItems = [UIAction]()
                        menuItems.append(UIAction(title: "Test") { action in
                            print("Test")
                        })
                        button.showsMenuAsPrimaryAction = true
                        button.menu = UIMenu(title: "", children: menuItems)
                    }
                }
            }
        }
    }
}

关于ios - UIContextualAction 显示 UIMenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67505799/

相关文章:

objective-c - iOS 本地化不加载语言

ios - 多维 NSArray 到 NSArray?

iOS Swift 蓝牙键盘按键检测

ios - 在 iOS 中,我可以跳转到另一个应用程序并使其使用帐户和密码自动登录吗?

ios - JSONModel:模型集合到JSON并手动添加集合

swift - Instagram 探索搜索栏和表格 View

swift - API滥用: Attempt to serialize store access on non-owning coordinator - with Assets. xcassets

xcode - 放弃更改后核心数据模型卡在 Logo 上

objective-c - 如何避免 NSArray 中的重复元素并在 TableView 单元格中打印

ios - 撤销分发证书是否会影响 Iphone 正在审查(在苹果商店)的应用程序?