Created
February 10, 2012 04:54
-
-
Save nicwise/1786782 to your computer and use it in GitHub Desktop.
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 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