public class TableViewSource<TEntity> : UITableViewSource
{
private IList<TEntity> _data;
public TableViewSource(IEnumerable<TEntity> data) {
this._data = data.ToList ();
}
public override int RowsInSection (UITableView tableview, int section)
{
return this._data.Count;
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
var cellIdentifier = GetCellIdentitfier(typeof(TEntity));
var cellView = tableView.DequeueReusableCell(cellIdentifier);
// bind data to cell view;
return cellView;
}
// Get cell identifer for Entity type
string GetCellIdentitfier (Type type)
{
switch (type) {
case type1:
return "type1-cell-identifier";
case type2:
return "type2-cell-identifier";
}
return "";
}
}