Created
February 15, 2013 22:01
-
-
Save yetanotherchris/4963909 to your computer and use it in GitHub Desktop.
Monotouch: UITableViewDataSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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