iOS Tables and Cells


Available table source classes in MvvmCross

Abstract classes

  • MvxBaseTableViewSource
    • base functionality only
    • no ItemsSource - generally not used directly
  • MvxTableViewSource.cs
    • inherits from the basetable and adds ItemsSource for data-binding
    • inheriting classes need only to implement protected abstract UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item);

Concrete classes

  • MvxStandardTableViewSource.cs
    • inherits from MvxTableViewSource
    • provides the ‘standard iPhone cell types’ via UITableViewCellStyle
    • within these you can bind TitleText, DetailText, ImageUrl and (with some teasing) Accessory
  • MvxSimpleTableViewSource.cs
    • inherits from MvxTableViewSource
    • provides a single cell type for all items in the collection - via string nibName in the ctor
    • within these cells you can bind what you like - see videos (later)
  • MvxActionBasedTableViewSource.cs
    • provides some Func<>style hooks to allow you to implement GetOrCreateCellFor without inheriting a new class from MvxTableViewSource

Custom table source example

A typical TableSource with multiple cell types typically looks like:

public class PolymorphicListItemTypesView : MvxTableViewController
    public PolymorphicListItemTypesView()
        Title = "Poly List";

    public override void ViewDidLoad()

        var source = new TableSource(TableView);
        this.AddBindings(new Dictionary<object, string>
                {source, "ItemsSource Animals"}

        TableView.Source = source;

    public class TableSource : MvxTableViewSource
        private static readonly NSString KittenCellIdentifier = new NSString("KittenCell");
        private static readonly NSString DogCellIdentifier = new NSString("DogCell");

        public TableSource(UITableView tableView)
            : base(tableView)
            tableView.RegisterNibForCellReuse(UINib.FromName("KittenCell", NSBundle.MainBundle),
            tableView.RegisterNibForCellReuse(UINib.FromName("DogCell", NSBundle.MainBundle), DogCellIdentifier);

        public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
            return KittenCell.GetCellHeight();

        protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath,
                                                              object item)
            NSString cellIdentifier;
            if (item is Kitten)
                cellIdentifier = KittenCellIdentifier;
            else if (item is Dog)
                cellIdentifier = DogCellIdentifier;
                throw new ArgumentException("Unknown animal of type " + item.GetType().Name);

            return (UITableViewCell) TableView.DequeueReusableCell(cellIdentifier, indexPath);


For examples of creating custom tables and cells: