Create the Table View in Your iOS App

Although powerful, Table views in iPhone and iPad apps are surprisingly easy to work with. To create a Table view, you follow only four — count ’em, four — steps, in the following order:

  1. Create and format the view itself.

    This includes specifying the Table style and a few other parameters, most of which you do in Interface Builder.

  2. Specify the Table view configuration.

    Not too complicated, actually. You let UITableView know how many sections you want, how many rows you want in each section, and what you want to call your section headers.

    You do that with the help of the numberOfSectionsInTableView:, tableView:numberOfRowsInSection:, and tableView:titleForHeaderInSection: methods, respectively.

  3. Supply the text (or graphic) for each row.

    You return that from the implementation of the tableView:cellForRowAtIndexPath: method. This message is sent for each visible row in the Table view, and you return a Table View cell to display the text or graphic.

  4. Respond to a user selection of the row.

    You use the tableView:didSelectRowAtIndexPath: method to take care of this task. In this method, you can create a view controller and push it onto the stack (as the storyboard does in a segue), or you can even send a message to the controller that presented a Modal View controller (or any other object).

A UITableView object must have a data source and a delegate:

  • The data source supplies the content for the Table view.

  • The delegate manages the appearance and behavior of the Table view.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.