-1

如何在 UIContextMenuConfiguration 中制作不可点击的菜单项?目前,当我单击菜单项时,什么也没有发生,菜单就关闭了。单击该项目时,我需要菜单不要关闭。

这是一些代码:

@available(iOS 13.0, *)
var contextMenuConfiguration: UIContextMenuConfiguration {
    let configuration = UIContextMenuConfiguration(
        identifier: nil,
        previewProvider: nil
    ) { [weak self] _ -> UIMenu? in
        guard let strongSelf = self else { return nil }

        var actions: [UIAction] = []
        actions.append(
            UIAction(title: "\(l10n(.id)) \(strongSelf.connection.id)",
                     image: UIImage(systemName: "info.circle")) { _ in
            strongSelf.delegate?.idPressed()
        })

这里是我的函数代码:

func idPressed() {
    <#code#>
}
4

1 回答 1

0

用下一个解决方案解决了这个问题:

    actions.append(
        UIAction(
            title: "\(l10n(.id)) \(strongSelf.connection.id)",
            image: UIImage(systemName: "info.circle"),
            attributes: .disabled) { _ in
            return
        }
    )
于 2021-07-29T13:51:11.850 回答