rac_signalForSelector fromProtocol,选择器不存在

时间:2015-09-05 20:01:59

标签: ios swift reactive-cocoa wkwebview

我试图使用Reactive Cocoa包装WKWebViewDelegate。

class WebContainerView: UIView, WKNavigationDelegate
{
let webView:WKWebView

required init(coder aDecoder: NSCoder){
    webView = WKWebView(frame: CGRect())
    super.init(coder: aDecoder)
    self.addSubview(webView)

    let proto = WKNavigationDelegate.self
    let selector:Selector = "webView(_:decidePolicyForNavigationAction:decisionHandler:)"
    let signal =   webView.rac_signalForSelector(selector, fromProtocol: proto).subscribeNext( { _ in
        println("Test")
    })
    webView.navigationDelegate = self
}}

但是我在创建信号时遇到此错误

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Selector webView(_:decidePolicyForNavigationAction:decisionHandler:) does not exist in <WKNavigationDelegate>'

选择器名称正是在委托方法中调用它的输出:

NSLog(%@, "__FUNCTION__")

1 个答案:

答案 0 :(得分:0)

我找到了这个错误的解决方案,正在改变这一行:

let selector:Selector = "webView(_:decidePolicyForNavigationAction:decisionHandler:)"

到此:

let selector:Selector = "webView:decidePolicyForNavigationAction:decisionHandler:"