Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created February 15, 2013 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4963909 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4963909 to your computer and use it in GitHub Desktop.
Monotouch: UITableViewDataSource
public class MainTableDataSource : UITableViewDataSource
{
private List<string> _items;
private string _section1CellId;
public MainTableDataSource()
{
_section1CellId = "cellid";
_items = new List<string>()
{
"Checked items demo",
"Various styles demo",
"Editable tables demo"
};
}
public override string TitleForHeader(UITableView tableView, int section)
{
return "Items";
}
public override int RowsInSection(UITableView tableview, int section)
{
return _items.Count;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
// For more information on why this is necessary, see the Apple docs
var row = indexPath.Row;
UITableViewCell cell = tableView.DequeueReusableCell(_section1CellId);
if (cell == null)
{
// See the styles demo for different UITableViewCellAccessory
cell = new UITableViewCell(UITableViewCellStyle.Default, _section1CellId);
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
}
cell.TextLabel.Text = _items[indexPath.Row];
return cell;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment