UITableView details - ParkinT/RubyMotion_Life GitHub Wiki
Whether static, or through a traditional dataSource, a table's cells aren't loaded and added as subviews of the table until after both viewDidLoad and viewWillAppear. Cell loading happens between viewWillAppear and viewDidAppear. A call to viewWithTag on a table can't return a subview of a cell until that cell has been added as a subview.
When your view loads, iOS hasn't yet asked your app for any cells or the contents. Your UITableViewController is the delegate for the UITableView dataSource, so it has to implement a minimum of three methods:
- def tableView(tableView, numberOfSectionsInTableView:section)
- def tableView(tableView, numberOfRowsInSection:section)
- def tableView(tableView, cellForRowAtIndexPath:indexPath)
iOS will only ask for the cells it needs to display, which makes things fast compared to having to populate every possible cell. Your application is in charge of determining what chunk of data will properly fill a cell at a given indexPath -- that is a row and column. So you handle this in tableView:cellForRowAtIndexPath:.
Most population of table cells is done by simply setting the UILabel text properties that correspond to the UITableViewCellStyle you selected. A couple of blog posts, with source code:
- A simple Twitter client using a straight UITableViewController derived class
- An example that subclasses UITableViewCell to provide custom fields
[Thanks to Dave Lee and Steve Ross in the Google Groups for this explanation]