/// <summary> /// <para>Extension method that binds an observable of a list of table /// sections as the source of a <see cref="UITableView"/>.</para> /// <para>If your <see cref="IReadOnlyList{T}"/> is also an instance of /// <see cref="INotifyCollectionChanged"/>, then this method /// will silently update the bindings whenever it changes as well. /// Otherwise, it will just log a message.</para> /// </summary> /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns> /// <param name="sectionsObservable">Sections observable.</param> /// <param name="tableView">Table view.</param> /// <param name="initSource">Optionally initializes some property of /// the <see cref="ReactiveTableViewSource{TSource}"/>.</param> /// <typeparam name="TSource">The source type.</typeparam> /// <typeparam name="TCell">Type of the <see cref="UITableViewCell"/>.</typeparam> public static IDisposable BindTo <TSource, TCell>( this IObservable <IReadOnlyList <TableSectionInformation <TSource, TCell> > > sectionsObservable, UITableView tableView, Func <ReactiveTableViewSource <TSource>, IDisposable>?initSource = null) where TCell : UITableViewCell { if (sectionsObservable is null) { throw new ArgumentNullException(nameof(sectionsObservable)); } if (tableView is null) { throw new ArgumentNullException(nameof(tableView)); } var source = new ReactiveTableViewSource <TSource>(tableView); if (initSource is not null) { initSource(source); } var bind = sectionsObservable.BindTo(source, x => x.Data); tableView.Source = source; return(new CompositeDisposable(bind, source)); }
/// <summary> /// <para>Extension method that binds an observable of a list of table /// sections as the source of a <see cref="UITableView"/>.</para> /// <para>If your <see cref="IReadOnlyList{T}"/> is also an instance of /// <see cref="Legacy.IReactiveNotifyCollectionChanged{T}"/>, then this method /// will silently update the bindings whenever it changes as well. /// Otherwise, it will just log a message.</para> /// </summary> /// <returns>The <see cref="IDisposable"/> used to dispose this binding.</returns> /// <param name="sectionsObservable">Sections observable.</param> /// <param name="tableView">Table view.</param> /// <param name="initSource">Optionally initializes some property of /// the <see cref="ReactiveTableViewSource{TSource}"/>.</param> /// <typeparam name="TSource">The source type.</typeparam> /// <typeparam name="TCell">Type of the <see cref="UITableViewCell"/>.</typeparam> public static IDisposable BindTo <TSource, TCell>( this IObservable <IReadOnlyList <TableSectionInformation <TSource, TCell> > > sectionsObservable, UITableView tableView, Func <ReactiveTableViewSource <TSource>, IDisposable> initSource = null) where TCell : UITableViewCell { var source = new ReactiveTableViewSource <TSource>(tableView); if (initSource != null) { initSource(source); } var bind = sectionsObservable.BindTo(source, x => x.Data); tableView.Source = source; return(new CompositeDisposable(bind, source)); }