In this recipe, we will discuss how to insert and delete rows at runtime from a UITableView
, providing the user with the appropriate user interface interaction.
Perform the following steps:
Remove the
tableData
field from theTableSource
class and replace it with the following property:public List<string> TableData { get; private set; }
Initialize the list in the constructor using the following code:
this.TableData = new List<string>() { "Music", "Videos", "Images" };
In the
TableSource
class, override theCommitEditingStyle
method and implement it with the following code:public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) { if (editingStyle == UITableViewCellEditingStyle.Delete) { this.tableData.RemoveAt(indexPath.Row); tableView.DeleteRows(new NSIndexPath[] { indexPath...