【问题标题】:UIWebView binding using ReactiveCocoa 4使用 ReactiveCocoa 4 的 UIWebView 绑定
【发布时间】:2016-02-25 12:22:06
【问题描述】:

我正在尝试我的第一个项目,使用反应性可可 4。在 ViewModel 中我有

var title = MutableProperty<String>("")

并且在ViewController 中是绑定的

self.articleDetailView.titleLabel.rac_text <~ self.articleViewModel.title

我正在使用 Colin Eberhardt (https://github.com/ColinEberhardt/ReactiveTwitterSearch/blob/master/ReactiveTwitterSearch/Util/UIKitExtensions.swift) 绑定 UIKit 扩展名。它适用于UILabel 等。

我的应用使用UIWebView,所以我需要绑定UIWebView。我不知道该怎么做。目前在我的非响应式代码中,我使用方法 loadHTMLString 将内容加载到我的 webView,但我不知道如何将 webView 与 ViewModel 绑定。

有人知道如何绑定UIWebView吗?

【问题讨论】:

    标签: ios swift mvvm uiwebview reactive-cocoa-4


    【解决方案1】:

    我在 github 上找到了答案。用户“雪崩”(https://github.com/avalanched)给我发这个例子:

    您可以将 MutableProperty 绑定到 loadHTMLString

    如果你在 ViewModel 中有这个

    var url : MutableProperty<NSURL>
    

    你可以这样绑定它:

    url.producer.map { NSURLRequest($0) }.startWithNext(webview.loadRequest)
    

    希望它对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-10-28
      • 2014-05-31
      • 2015-07-26
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多