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

    OXOCube75 macrumors newbie

    Apr 13, 2011
    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

    #import <UIKit/UIKit.h>
    @interface RootViewController : UITableViewController 
    <UITableViewDataSource, UITableViewDelegate> 
        NSArray *filmmakers;
        NSArray *role;
        NSArray *niba;
    @property (nonatomic, retain) IBOutlet NSMutableArray *nibx;
    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

    - (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.


  2. Shawnpk, Apr 13, 2011
    Last edited by a moderator: Apr 13, 2011

    Shawnpk macrumors 6502

    Jan 13, 2011
    Los Angeles, CA
    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. OXOCube75 thread starter macrumors newbie

    Apr 13, 2011
    That worked great.


Share This Page