Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

OXOCube75

macrumors newbie
Original poster
Apr 13, 2011
3
0
Hi there,

I'm trying to code a navigation app using table views to give a list of names and when the persons table cell is selected it brings up a nib for that person.

So far I've been able to create the tables, populate it with data from an array and get when a cell is selected to change the view to a different nib. what I want to do is be able to navigate to a different nib file based on the cell selected.

My root view controller code is

Code:
#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController 
<UITableViewDataSource, UITableViewDelegate> 
{
    NSArray *filmmakers;
    NSArray *role;
    NSArray *niba;
    
    
}

@property (nonatomic, retain) IBOutlet NSMutableArray *nibx;

@end

The Cell Textlabel is pulled from the filmmakers array and the subtitle is pulled from the role array.

The code I'm using in the rootviewcontroller.m specific to changing the view is

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    anotherViewController *filmmakerViewController = [[anotherViewController alloc] initWithNibName:@"JenViewController" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:filmmakerViewController animated:YES];
    [filmmakerViewController release];
What I would like to do is be able to have the initWithNibName pull from the niba array based on cell selection so instead of "JenViewController" it would insert "PeterViewController" if the Peter cell was selected.

Any help would be appreciated.

Thanks!!

Stuart
 
Last edited by a moderator:
You can use [indexpath row] in an if statement, along with the number of the row, to get the row of the tableview that is selected. Then you can push the different views.
 
Last edited by a moderator:
You can use [indexpath row] in an if statement, along with the number of the row, to get the row of the tableview that is selected. Then you can push the different views.

That worked great.

Thanks!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.