Created
September 21, 2011 19:51
-
-
Save SuperYeti/1233106 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using MonoTouch.UIKit; | |
using MonoTouch.Foundation; | |
using MonoTouch.Dialog; | |
using MonoTouch.Dialog.Extensions; | |
namespace SimcoeCabinets | |
{ | |
public class EditingDialog : SpiffyDialogViewController { | |
// This is our subclass of the fixed-size Source that allows editing | |
public class EditingSource : DialogViewController.Source { | |
public EditingSource (EditingDialog dvc) : base (dvc) {} | |
public override bool CanEditRow (UITableView tableView, NSIndexPath indexPath) | |
{ | |
var section = Container.Root [indexPath.Section]; | |
var element = section [indexPath.Row]; | |
DBBase item = element.DataItem as DBBase; | |
if(item != null) | |
{ | |
return item.Active; | |
} | |
// Trivial implementation: we let all rows be editable, regardless of section or row | |
return true; | |
} | |
public override UITableViewCellEditingStyle EditingStyleForRow (UITableView tableView, NSIndexPath indexPath) | |
{ | |
// trivial implementation: show a delete button always | |
return UITableViewCellEditingStyle.Delete; | |
} | |
public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) | |
{ | |
// | |
// In this method, we need to actually carry out the request | |
// | |
var section = Container.Root [indexPath.Section]; | |
var element = section [indexPath.Row]; | |
try | |
{ | |
element.DeleteSource(); | |
section.Remove (element); | |
} | |
catch (Exception ex) | |
{ | |
Container.ReloadData(); | |
Console.WriteLine("EditingDialog::CommitEditingStyle failed. Error Message: " + ex.Message); | |
} | |
} | |
} | |
public class EditingSizingSource : EditingSource { | |
public EditingSizingSource (EditingDialog dvc) : base (dvc) {} | |
} | |
public override Source CreateSizingSource (bool unevenRows) | |
{ | |
if (unevenRows) | |
return new EditingSizingSource(this); | |
return new EditingSource (this); | |
} | |
public EditingDialog (RootElement root, bool pushing, UIImage bgImage) : base (root, pushing, bgImage){} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment