【问题标题】:Cannot invoke 'performSelector' with an argument list of type '(String)'无法使用类型为“(字符串)”的参数列表调用“执行选择器”
【发布时间】:2016-06-14 10:57:52
【问题描述】:

我正在使用 xcode 8 beta 并遇到错误且无法解决。

无法使用“(字符串)”类型的参数列表调用“performSelector

func webView(WebViewNews: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {

     if request.URL!.absoluteString.hasPrefix("ios:") {
        // Call the given selector
          self.performSelector("webToNativeCall")
       // Cancel the location change
          return false
       }
        return true
 }

【问题讨论】:

  • 请发布您的完整课程。具有选择器webToNativeCall 的对象是什么?为什么不直接在self 上调用函数呢?你不应该为此需要performSelector

标签: ios xcode swift swift3 xcode8


【解决方案1】:

performSelector 已重命名为perform(_ aSelector:)

class SomeClass: NSObject {

    func webToNativeCall() {
        // ...
    }

    func someFunc() {
        self.perform(#selector(webToNativeCall))
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多