This screencast shows the end-to-end process of how to create a simple iPhone application with MonoTouch. The application displays data in a table, and gives the user the ability to delete cells from the table.
The application consists of a UINavigationController, a UITableViewController and of course some UITableViewCells which can be deleted from their containing table.
Some things I mention in the screencast are:
- Just like in my UINavigationController RSS example, I am using a template for UITableViewControllers which is based on the one I found at Code Snack.
- Swipe to delete is enabled simply by overriding the CommitEditingStyle method in your UITableViewDataSource class.
The key bit of code from this example is the CommitEditingStyle method:
class DataSource : UITableViewDataSource
{
EmployeesTableViewController tvc;
// ...
public override void CommitEditingStyle(UITableView tableView,
UITableViewCellEditingStyle editingStyle,
NSIndexPath indexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
tvc.Employees.RemoveAt(indexPath.Row);
tableView.DeleteRows(new [] { indexPath }, UITableViewRowAnimation.Fade);
}
}
// ...