views:

71

answers:

2

Hi, Noob at the most.

I just filled my UITableView with Planets. I would like each cell clicked to open into a new Xib (if this sounds like the wrong approach please direct). I can get a secondviewcontroller working, its getting the thirdviewcontroller and fourthviewcontroller working? Thanks.

+1  A: 

Place your main view controller (the one with the table) inside a UINavigationController. Then, when the user selects a row, push a new view controller onto it.

Ben Gottlieb
+1  A: 

The following function will help. As Ben Gottlieb said your main view controller will need to be in a UINavigationController. You need to implement the delegate method for didSelectRowAtIndexPath and this is where you create the new controller for your new view and load it.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        YourViewController *controller =  [[YourViewController alloc] initWithNibName:@"YourViewController"bundle:nil];         
        [[self navigationController] pushViewController:yourViewController animated:YES];   
        [yourViewController release]; // don't leak memory
        }

Based on the row number you can decide which nib to load.

NeilInglis
Thanks Neilngils and Ben. I play around with it and added a IF statement, not sure if this is the correct approach but it works. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int RowCount = [indexPath row]; if (RowCount == 0){ EarthViewController *earthViewController = [[EarthViewController alloc] initWithNibName:@"EarthViewController"bundle:nil]; [[self navigationController] pushViewController:earthViewController animated:YES]; [earthViewController release]; // don't leak memory } else if (RowCount ==1){ .....
Goods