Skip to content

Instantly share code, notes, and snippets.

@nicwise
Created February 10, 2012 04:54
Show Gist options
  • Save nicwise/1786782 to your computer and use it in GitHub Desktop.
Save nicwise/1786782 to your computer and use it in GitHub Desktop.
public class EditingSource : DialogViewController.Source
{
RecordsDialogViewController tvc = null;
public EditingSource(RecordsDialogViewController dvc) : base(dvc)
{
tvc = dvc;
}
public override bool CanEditRow (UITableView tableView, NSIndexPath indexPath)
{
return true; //indexPath.Section == 0;
}
public override UITableViewCellEditingStyle EditingStyleForRow (UITableView tableView, NSIndexPath indexPath)
{
if (tvc.Editing)
{
return UITableViewCellEditingStyle.Delete;
}
return UITableViewCellEditingStyle.None;
}
public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
//
// In this method, we need to actually carry out the request
//
//need to remove the item at indexPath.Row
var section = Container.Root [indexPath.Section];
var element = section [indexPath.Row];
// I have a custom Element - you could use StringElement or Element here.
var recordElement = element as RecordsElement;
if (recordElement != null)
{
//remove it from your database!--> TransactionWriter.Delete(recordElement.Transaction);
section.Remove (element);
if (section.Count == 0)
{
Container.Root.Remove(section);
}
}
}
}
public override Source CreateSizingSource (bool unevenRows)
{
//if (unevenRows)
// throw new NotImplementedException ("You need to create a new SourceSizing subclass, this sample does not have it");
return new EditingSource (this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment