Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can create multiple custom subclasses of UITableViewCell, and in the <a href="http://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDataSource/tableView%3acellForRowAtIndexPath%3a" rel="nofollow">tableView:cellForRowAtIndexPath:</a> method for your UITableViewDataSource, you can use if-statements to determine what type of cell to use.</p> <p>For example, here's a rough outline of what I might do:</p> <pre><code>-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //First, determine what type of object we're showing if (indexPath.section == 0) { //Create and return this cell. } else if (indexPath.section == 1) { //Create and return this cell. }... } </code></pre> <p>Here's how you'd implement <code>numberOfRowsInSection</code>:</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) { return [firstSectionArray count]; } else if (section == 1) { return [secondSectionArray count]; } ... } </code></pre> <p>For <code>didSelectRowAtIndexPath</code></p> <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { ObjectSelected *objectSelected = [firstArray objectAtIndex:indexPath.row]; //Now you've got the object, so push a view controller: DetailViewController *dvc = [[DetailViewController alloc] init]; dvc.objectSelected = objectSelected; [self.navigationController pushViewController:dvc]; } else if (indexPath.section == 1) { //Same thing, just call [secondArray objectAtIndex:indexPath.row] instead! } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload