Why won't self.navigationController pushViewController work?

28,788

Solution 1

In UIBuilder verify that UINavigationController is referenced by the File's owner.

Solution 2

Got it.

I changed the Architecture a little bit.

I made a New UIViewController class with its xib. And coded new UINavigationController.

- (void)viewDidLoad {
[super viewDidLoad];
    UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];   


switch (whichViewController) {
    case 1:
        viewController = [[xxxx alloc] init];           
        break;
    case 2:
        viewController = [[xxx1 alloc] init];           
        break;
    default:
        break;
}

[navigationController pushViewController:viewController animated:NO];
[viewController release];

}

And pushing the view in the Switch Statement....

I hope this makes sense ......

Thanks jamihash

Solution 3

So you are adding the tableview to the navigation controller right? This is how:

tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

navigationController = [[UINavigationController alloc] init];

[navigationController pushViewController:tableView animated:NO];

The tableview gets added as the rootview to the navigation controller. And then on selecting a row if you wish to push another viewcontroller use the

self.navigationController pushViewController: newViewController animated:YES]; 

inside the didSelectRowAtIndex method.

NOTE: its UITableViewController *tableView and UINavigationController *navigationController by declaration. So code accordingly for your table.

Share:
28,788
trio
Author by

trio

Updated on June 17, 2020

Comments

  • trio
    trio almost 4 years

    I have a

    UIViewController-> UINavigationBar + UITableView

    Just a bit more explanation

    I made it through UIBuilder..

    1: Created a New UIViewController with XIB-file
    2: Using UIBuiler i put a UINavigationController
    3: Then i put UITableView underneath the navigationBar so it gave me..

    A: UIViewController-> UINavigationBar + UITableView

    Now i am loading the data in UITableView from a Webservice which is working fine.

    I again made a xib with sam config which is

    B: UIViewController-> UINavigationBar + UITableView

    So now when i try to push view B on view A using below code...it wont at all work...

    SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil];
    
    [self.navigationController pushViewController:siteViewController animated:YES];
    

    When i checked the UINavigationController *nav = self.navigation

    nav is 0x0 that is i assume NIL.

    Can anybody tell me whats wrong in here.. why is it nil...and how can i make it work..

    Thanks a Lot....I would really appreciate any help

  • trio
    trio over 13 years
    When you drop a UINavigationBar from UIBuilder library is it a UINavigationController? It is a UINavigationBar.
  • trio
    trio over 13 years
    No no... I created a new file that is UIViewController with XIB option Selected. For ex: @interface ClasssName : UIViewController <some delegates>{ } So it is a Subclass of UIViewController Now i opened the xib file and drop UINavigationBar Then i drop UITableView onto the xib file which is UIViewController Does this help?
  • jamihash
    jamihash over 13 years
    Its just the bar that appears in the view. You need to either drag and drop UINavigationController in UIBuilder and hook it up to the File's owner's navigation controller. Or you could create in the code.
  • trio
    trio over 13 years
    Hey can i send you the code ....I tried but couldn't figure out...I would really appreciate any help...Thanks Man
  • jamihash
    jamihash over 13 years
    I would highly recommend you read "Head First Iphone Development". It is really well written and has examples of exactly what you are trying to do. It will save you countless hours and help you get productive fast.