for*_*got 2 reactive-cocoa swift3
作为这个问题的后续,收到了这个梦幻般的答案,并使用以下示例...
class Model {
let mapType = MutableProperty<MKMapType>(.standard)
}
class SomeViewController: UIViewController {
let viewModel: Model
var mapView: MKMapView!
init(viewModel: Model) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
mapView = // Create the map view
viewModel.mapType.producer.startWithValues { [weak self] mapType in
self?.mapView.mapType = mapType
}
// Rest of bindings
}
// The rest of the implementation...
}
class SomeOtherViewController: UIViewController {
let viewModel: Model
var segmentedControl: UISegmentedControl!
init(viewModel: Model) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
// Pretend we've setup the segmentedControl, and set its action to `updateMap(sender:)`...
// The rest of the initialization...
}
func updateMap(sender: UISegmentedControl) {
let newMapType =...
self.viewModel.mapType = newMapType // How do I update this value?
}
// The rest of the implementation...
}
Run Code Online (Sandbox Code Playgroud)
如何更新值Model.mapType,并将其更改发送给任何观察者(如SomeViewController示例中所示)?
| 归档时间: |
|
| 查看次数: |
1288 次 |
| 最近记录: |