我正在学习本教程https://kylebashour.com/posts/context-menu-guide,并试图重新利用提供上下文菜单的代码段:
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])
并确保其子级具有.disabled
属性集。
UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up", , attributes: .disabled)
有没有一种方法可以更新已经显示的上下文菜单的标题及其子级的属性?