【发布时间】:2019-03-12 08:49:23
【问题描述】:
如果术语被关闭,我们深表歉意;我是一名 iOS 开发人员,必须使用 Xamarin.iOS 来开发应用程序。我正在使用带有 DynamicData 和 MVVM 架构的 ReactiveUI。总的来说,我对 RxSwift 和 FRP 概念相当满意。根据文档,我有一个发布SourceList<MyThing> 的模型,如下所示:
// Property declarations
private readonly SourceList<MyThing> Things;
public IObservableCollection<MyThing> ThingsBindable { get; }
// Later, in the constructor...
Things = new SourceList<MyThing>();
// Is this of the right type?
ThingsBindable = new ObservableCollectionExtended<MyThing>();
Things
.Connect()
.Bind(ThingsBindable)
.Subscribe();
我可以在我的视图(即 iOS 领域的 ViewController)中成功使用 .BindTo() 来获取 UITableView 以在模型更改时更新:
Model
.WhenAnyValue(model => model.ThingsBindable)
.BindTo<MyThing, MyThingTableViewCell>(
tableView,
new NSString("ThingCellIdentifier"),
46, // Cell height
cell => cell.Initialize());
我希望 ViewModel 订阅并发布(或以其他方式代理)SourceList<MyThing> 或 this 的可绑定版本,而不是直接绑定到模型,以便视图仅使用视图模型属性。 SourceList 在文档中声明为 private;我不确定这里的最佳实践:我是否将其公开并在 ViewModel 中执行我的Connect()?或者有没有办法从 ViewModel 传递公开暴露的IObservableCollection<MyThing> ThingsBindable?我也不相信 ObservableCollectionExtended<MyThing> 是 Bindable 属性的正确类型,但它似乎有效。
我尝试了.ToProperty()、.Bind()、.Publish() 等的各种组合,并在 ViewModel 中制作了一个 View-binding Observable 版本,但无济于事,现在我只是将自动完成功能扔到墙上看看什么坚持。任何方向表示赞赏。 TIA。
【问题讨论】:
-
通常 ReadOnlyObservableCollection 是您用于 Bind() 的类型,但在需要绑定列表支持的 winform 上除外。通常 SourceList 也是私有的,因为它不应该在您的视图中使用。您可以公开 Connect() 方法和它产生的
IObservable<IChangeSet<T>>。
标签: ios xamarin.ios dynamic-data reactiveui xamarin.ios-binding