views:

170

answers:

3

Hello All,

I know its possible to create a table that has an index on the side and a search bar at the top that a user can type in to find an item, but is it possible to say to the table if array isEqual to "item1" push view1? I would like to push a different view with each cell. Anyone have any advice?

+2  A: 

Sure. Just create the appropriate view (controller) depending on the cell's indexPath in tableView:didSelectRowAtIndexPath:.

Ole Begemann
I found a country tutorial on it and tried this code but nothing happened. if ([[listOfItems objectAtIndex:indexPath.row] isEqual:@"Iceland"]) { //Initialize the detail view controller and display it. Test *dvController = [[Test alloc] initWithNibName:@"Test" bundle:nil]; [self.navigationController pushViewController:dvController animated:YES]; }
Tanner
A: 

Check out the sample programs from the book Beginning iPhone Development. You must sign up, but its free. You should look specifically at chapter 9's sample code called Nav. Shows you exactly what you need. This was my first book on the subject and was well worth it.

http://www.iphonedevbook.com/forum/viewforum.php?sid=3010c045df967353c6b3894889e6b8f5

Cheers! Ken

Kenny
When I clicked the link it said the page does not exist. I do however have the book. The sections 2 part loads from a plist and doesnt push anything though.
Tanner
A: 

Create the cell based on the index path. If you create all the cells ahead of time, store them in an array by row index. If you are creating them as needed, do something like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *result;
    switch ( [indexPath row] ) {
    default: result = [self tableView:tableView normalCellForRowAtIndexPath:indexPath]; break;
    case 3: result = [self tableView:tableView detail3CellForRowAtIndexPath:indexPath]; break;
    case 5: result = [self tableView:tableView detail5CellForRowAtIndexPath:indexPath]; break;
    }
    return result;
}
drawnonward
So make every cell from the index paths and not an array? How would the cells distinguish "A" from "B" and other indexes from the right side of the table?
Tanner