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

Table indexing


In this recipe, we will learn how to provide an index in a table, allowing the user to quickly browse through the rows of UITableView.

Getting ready

Create a new project in Xamarin Studio and name it TableIndexApp. Add a UITableViewController, as shown in the previous tasks in this chapter, and implement the TableSource class.

How to do it...

Perform the following step:

  1. In the table source class, override and implement the following methods:

    public override int NumberOfSections (UITableView tableView)
    {
      return this.tableData.Count;
    }
    public override string TitleForHeader (UITableView tableView, int section)
    {
      return Convert.ToString (this.tableData[section][0]);
    }
    public override string[] SectionIndexTitles (UITableView tableView)
    {
      return this.tableData.Select (s => Convert.ToString (s[0])).Distinct ().ToArray ();
    }

How it works...

The table source created in this recipe contains many different sections. For simplicity, each section contains one row. The NumberOfSections...