User Tools

Site Tools


ios-labs-s14:basics-tables

This is an old revision of the document!


UITableView

An extremely common, and slightly more complex, view used to build interfaces.

Displays a set of data in cells, which the developer sets the number of. Allows a user to scroll through cells vertically.

Requires 3 pieces of information to function: the number of sections in the table, number of cells in each section, and the contents of each cell.

Relies on delegation to communicate with a controller and determine functionality based on the above. Also uses delegation to alert a controller when a user touches a cell.

The delegate methods required by a UITableView:

  • -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
  • -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

Return integers to the table.

  • -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Method receives a cell that is dequeued from memory (has been scrolled off the screen and is no longer visible) for editing. Method is called when the table needs to display a new cell. Developer must change the views within the cell to represent model information, commonly using indexPath.row as an index into an array. Cell is returned at the end of the method, at which point the table loads it into memory and onto the screen.

Note that cells have a property called reuse identifier, a string used to identify types of cells in the case of multiple tables. Set this property using the Attributes Inspector of InterfaceBuilder, access it in the cellForRowAtIndexPath method.

  • -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Called when a user touches a cell. Includes the index of the touched cell in indexPath.row.

ios-labs-s14/basics-tables.1392655788.txt.gz · Last modified: 2014/02/17 10:49 by mbarboi