Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Editing a table


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.

Getting ready

Open the CustomRowsApp project we created in the previous recipe, Customizing rows.

How to do it...

Perform the following steps:

  1. Remove the tableData field from the TableSource class and replace it with the following property:

    public List<string> TableData { get; private set; }
  2. Initialize the list in the constructor using the following code:

    this.TableData = new List<string>() { "Music", "Videos", "Images" };
  3. In the TableSource class, override the CommitEditingStyle 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...