views:

194

answers:

2

I have 2 XIBs with their corresponding View Controllers. Will call them MainViewController and AboutViewController. The names of the XIBs are exactly the same as the names of the ViewControllers. Upon a button click in the MainViewController, I want to show the AboutViewController.

I have code like this in the MainViewController:

- (IBAction) infoButtonAction:(id)sender {
    AboutViewController *aboutViewController = [[AboutViewController alloc] init];
    [[self navigationController] pushViewController:aboutViewController animated:YES];
}

But nothing happens, the AboutViewController does not show up. I also tried this line:

AboutViewController *aboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];

But to no avail. What am I missing?

A: 

do you get an error? Did you check that the button is correctly wired in IB?

did you try using a modal view controller?

ennuikiller
I don't get any errors. The button is correctly wired, because it stops on a breakpoint inside the click function.
AngryHacker
+1  A: 

Examine your AboutViewController.xib in Interface Builder and ensure that the File Owner is set to AboutViewController in the class inspector. Also ensure that the view property of the File Owner is wired into the View in the xib. Finally, the code to display it should read:

- (IBAction) infoButtonAction:(id)sender {
    AboutViewController *aboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
    [[self navigationController] pushViewController:aboutViewController animated:YES];
    [aboutViewController release];
}

Also, you should check that this is non-nil inside that same method:

UINavigationController * nc = self.navigationController;
Jason
You are right. The self.navigationController is nil. Can you tell me why and what I can do about it?
AngryHacker
That means your MainViewController is not inside a navigationController. You will need to examine how you create your MainViewController.
Jason