我正在将我在 Obj-C 中的项目移植到 Swift 中,但我被困在这个方法中:
textView: NSTextView, doCommandBySelector commandSelector: Selector) -> BOOL
在我之前的目标代码中
[textView performSelector:commandSelector withObject:nil];
但在 Swift 中我不知道解决方案,如何实际编写代码行。
谁有解决办法?
上周我真的快要疯了,即使在阅读了大量文档之后也是如此。
谢谢
最佳答案
即使在 Objective-C 中,您也必须为此使用方法 -[UIApplication sendAction:to:from:forEvent:]
所以在 Swift 中尝试这样的事情:
UIApplication.sharedApplication()
.sendAction(commandSelector, to: textView, from: self, forEvent: nil)
有关 Apple Dev Forums 的更多信息.
关于Swift 动态选择器调用(旧的 performSelector :),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28823712/