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

Displaying data in a table


In this recipe, we will learn how to use the UITableView class to display data. This class, along with the UITableViewCell object, provides an interface for displaying data on the screen in multiple rows, but on a single column.

Getting ready

To get started, create a new project in Xamarin Studio and name it TableViewApp. In this recipe, we will not use the XIB files. We will create our user interface in code.

How to do it...

Perform the following steps:

  1. Add a new class to the project and name it TableController. Derive the class from UITableViewController using the following code:

    public class TableController : UITableViewController
  2. Create the following nested class inside the TableController class:

    private class TableSource : UITableViewSource
    {
      public TableSource ()
      {
        this.cellID = "cellIdentifier";
        this.tableData = new Dictionary<int, string> () {
          {0, "Music"},
          {1, "Videos"},
          {2, "Images"}
        };
      }
      private readonly string cellID...