Creating a custom table view controller

In this recipe we will learn how to create a subclass of the UITableViewController class, and use it to populate a UITableView controller.

Getting ready

The UITableViewController classes are a perfect way of providing you with the flexibility to manage a table view, and providing the functionality of adding to our base controller the ability of sharing its inheritor classes. For this to happen, we will need to incorporate the methods for a UITableView class.

How to do it...

To begin, we will need to create a new Xcode project. This can be achieved by performing the following simple steps:

  1. Create a new Single View Application project and name it TableViewExample.
  2. Next, select the TableViewExample folder, select File | New | New File… or press command + N.
  3. Select the Objective-C class template from the list of templates.
  4. Click on the Next button to proceed to the next step in the wizard.
  5. Enter TableViewController as the name of the file to create.
  6. Ensure that you have selected UITableViewController as the type of subclass to create from the Subclass drop-down menu.
  7. Ensure that the Targeted for iPad checkbox is not checked.
  8. Ensure that the With XIB for User Interface checkbox is not checked.
  9. Click on the Next button to proceed to the next step of the wizard.
  10. Click on the Create button to save the file to the specified folder location.

How it works…

What we have done here is add a new TableViewController class to our TableViewExample application that provides us with the necessary table view methods we can use to interact with the TableView control.

See also

  • The Adding a table view to a view controller recipe
  • The Using Xcode to create an iOS project recipe in Chapter 1, Getting and Installing the iOS SDK Development Tools
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset