TableViews A UItableView displays a table (list) of cells. They are arranged vertically. There is just one column. The table view handles all aspects of displaying the cells, including scrolling and handling the user's selection of a cell. The table is divided into sections. Each section has a header and footer, which may be null, and zero or more cells. You choose the size and content of each cell. Since a table view is a very general purpose mechanism it needs to be configured for your particular needs. It does this by calling its delegates for information. 1) When first created, the tableView asks its delegate how many sections and rows are in the table. For sections it calls numberOfSections. For rows it calls numberOfRowsInSection and tells you which section. You return the number. 2) When the cell is to be drawn the tableView will call its delegate and request the content of the cell. It does this by calling cellForRowAtIndexPath and giving you the index path (indexPath.row and indexPath.section). You return the appropriate cell. Cells exist only when they are visible on the screen. When the are scrolled off, they are removed from the table view and placed in a queue. When a cell is scrolled into view the above routine should first examine the queue to see if an acceptable cell is there. If so, it will take it and replace the content to make a cell for this location. If not it must create a cell. 3) When the user selects a cell in the screen, the tableView will call its delegate with didSelectRowAtIndexPath. In that routine you take the action appropriate for the selection. These three routines must agree on the number of sections and rows. See the Table View Programming Guide. The page was last updated
Thursday, November 3, 2011 11:28 AM
|