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.
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.
Perform the following steps:
Add a new class to the project and name it
TableController
. Derive the class fromUITableViewController
using the following code:public class TableController : UITableViewController
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...