我正在尝试从 UIMenuController中删除项目Look Up & Share...。我将如何专门删除这两个并保留我的自定义一个。这是我到目前为止所取得的成就:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// add two custom menu items to the context menu of UIWebView (assuming in contenteditable mode)
let menuItem1 = UIMenuItem(title: "My Button", action: #selector(myButtonSel))
UIMenuController.shared.menuItems = [menuItem1]
}
这是我拥有的 canPerformAction:
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
//let shareSelector: Selector = NSSelectorFromString("_share:")
if webView?.superview != nil {
if action == #selector(myButtonSel){
return true
}
}
return super.canPerformAction(action, withSender: sender)
}
同样出于某种奇怪的原因,当我尝试删除所有默认项目并仅保留我的自定义项时,它不起作用。这是我为此尝试的代码:
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
//let shareSelector: Selector = NSSelectorFromString("_share:")
if webView?.superview != nil {
if action == #selector(myButtonSel){
return true
}
else {
return false
}
}
return super.canPerformAction(action, withSender: sender)
}
即使我尝试删除所有其他项目并保留我的习惯,我也无法这样做。我所能做的就是添加我的自定义项目。