Skip to content

Instantly share code, notes, and snippets.

@chkimes
Last active August 29, 2015 14:02
Show Gist options
  • Save chkimes/ad6d8ee6bf4edf3f3ff0 to your computer and use it in GitHub Desktop.
Save chkimes/ad6d8ee6bf4edf3f3ff0 to your computer and use it in GitHub Desktop.
public class MvxCustomTableViewSource<T> : MvxTableViewSource where T : UITableViewCell
{
private readonly string _cellIdentifier;
public MvxCustomTableViewSource(UITableView tableView) : this(tableView, typeof(T).ToString())
{
}
public MvxCustomTableViewSource(UITableView tableView, string cellIdentifier) : base(tableView)
{
_cellIdentifier = cellIdentifier;
tableView.RegisterClassForCellReuse(typeof(T), new NSString(cellIdentifier));
}
[Obsolete("Unsupported", true)]
public MvxCustomTableViewSource(IntPtr handle) : base(handle)
{
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
return tableView.DequeueReusableCell(_cellIdentifier);
}
}
public class SomeViewController : MvxViewController
{
...
private void SetUpTable()
{
var tableView = new UITableView();
Add(tableView);
var source = new MvxCustomTableViewSource<MyCustomTableViewCell>(_tableView);
tableView.Source = source;
var set = this.CreateBindingSet<SomeViewController, SomeViewModel>();
set.Bind(source).To(vm => vm.SomeCollection);
set.Apply();
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment