如何在已经显示的上下文菜单中更新值?

 收藏

I'm following this tutorial https://kylebashour.com/posts/context-menu-guide and am trying to repurpose this snippet which presents a context menu:

class TableViewController: UITableViewController {
    let data: [MyModel] = []

    override func viewDidLoad() {
        super.viewDidLoad()

        // Configure the table view
    }

    override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
        let item = data[indexPath.row]

        return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { suggestedActions in

            // Create an action for sharing
            let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { action in
                print("Sharing \(item)")
            }

            // Create other actions...

            return UIMenu(title: "", children: [share, rename, delete])
        }
    }
}

出现上下文菜单后5秒钟,我想更新菜单的标题

UIMenu(title: "expired", children: [share, rename, delete])

and ensure its children have the .disabled attributed set.

UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up", , attributes: .disabled)

有什么方法可以更新已经显示的上下文菜单的标题及其子级的属性?

回复