UIMenuItem选择器方法在iOS 11 beta SDK中崩溃。
-WKContentView highlightText:未识别的选择器发送到实例0x7f85df8f3200
方法定义:
func highlightText()
{
//
}我尝试在UIMenuItem中添加WKWebView,
let menuItemHighlight = UIMenuItem.init(title: "Highlight", action: #selector(ContentWebkitView.highlightText))
UIMenuController.shared.menuItems = [menuItemHighlight]发布于 2018-04-10 19:28:09
当我重写canPerformAction并检查我的自定义选择器时,我也得到了这个错误。在我的例子中,除了我的自定义菜单项之外,我想删除所有的菜单项。
class ViewController: UIViewController {
@IBOutlet weak var webView: MyWebView!
override func viewDidLoad() {
super.viewDidLoad()
loadWebView()
setupCustomMenu()
}
func loadWebView() {
let url = URL(string: "http://www.google.com")
let request = URLRequest(url: url!)
webView.load(request)
}
func setupCustomMenu() {
let customMenuItem = UIMenuItem(title: "Foo", action:
#selector(ViewController.customMenuTapped))
UIMenuController.shared.menuItems = [customMenuItem]
UIMenuController.shared.update()
}
@objc func customMenuTapped() {
let yay = ""
let alertView = UIAlertController(title: "Yay!!", message: yay, preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "cool", style: .default, handler: nil))
present(alertView, animated: true, completion: nil)
}
}
class MyWebView: WKWebView {
// turn off all other menu items
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return false
}
}发布于 2018-03-16 14:46:02
好了,我们终于让它适用于Swift 4:
现在,UIMenuItem按预期工作:

但老实说,这真的像是一次黑客攻击,我希望苹果能解决这个问题:-/
感谢斯蒂芬-海尔纳的回答:https://stackoverflow.com/a/42985441/4670400
https://stackoverflow.com/questions/45538886
复制相似问题