initWithNibName issue

Discussion in 'iOS Programming' started by OXOCube75, Apr 13, 2011.

  1. OXOCube75, Apr 13, 2011
    Last edited by a moderator: Apr 13, 2011

    macrumors newbie

    Joined:
    Apr 13, 2011
    #1
    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
     
  2. Shawnpk, Apr 13, 2011
    Last edited by a moderator: Apr 13, 2011

    macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Apr 13, 2011
    #3
    That worked great.

    Thanks!!
     

Share This Page