我想使用UITextView的UIMenuItem自己的属性“查找”。
我的下面的代码:
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(copy(_:)) {
return true
} else if action.description == "_share:" {
return false
} else if action.description == "_define:" {
return true
} else {
return super.canPerformAction(action, withSender: sender)
}
}
但是当我点击“查找”时,我也想做任何事情。
所以我添加了一个新的UIMenuItem尝试自定义一个按钮。
以下代码:
UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm: word)
let controller = UIReferenceLibraryViewController(term: word)
present(controller, animated: true, completion: nil)
从上面的代码中,我发现UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm: word)
或UIReferenceLibraryViewController(term: word)
将花费很多时间,然后显示当前的视图控制器。这不是我期望的。
调试日志也很奇怪:
2019-12-19 15:02:07.990304+0800 Apach3Test[2293:3172218] Got the query meta data reply for: com.apple.MobileAsset.DictionaryServices.dictionary2, response: 0
2019-12-19 15:02:08.025661+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.046067+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.066131+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.087073+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.106500+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.126552+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.146229+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.166038+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.186365+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.206932+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.226399+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.246282+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.266028+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.285836+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.306096+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.326436+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.345946+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.365660+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.385292+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.404927+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.424573+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.444016+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.463577+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.483812+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.503637+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.523129+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.542897+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.562987+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.582491+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.602096+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.622431+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.643826+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.664131+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.684049+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.704128+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.723603+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.743981+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.765215+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.785537+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.805865+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.826106+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.846475+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.867265+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.888123+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.908901+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.929594+0800 Apach3Test[2293:3172218] Old state: 2 new state:2
2019-12-19 15:02:08.950167+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.971126+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:08.991358+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.011937+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.032730+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.052874+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.073563+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.094293+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.115254+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.136170+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.156811+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
2019-12-19 15:02:09.177521+0800 Apach3Test[2293:3172218] Old state: 1 new state:1
它们是什么意思?
他们在做什么?
谁能告诉我...我对此很困惑...
当我调用私有方法_define
时我只是想听,有什么办法可以存档吗?
谢谢