I created a View-Based Application in XCode. On the main view there is a UIButton. Then I created a second view called View2.xib which has the UILabel that says “Second View”.
Now, all I want to do is display the second view when you click on the button. In the view controller class for the first view that contains the button I added.
#import View2ViewController.h
…
View2ViewController *View2;
…
And I added the property for this. This class also has the IBAction for the button click event, which works just fine and executes when clicked. Now, in the .m file I obviously @synthesize View2; and begin to edit the button click method to display the view. Here is the code:
if(self.View2 == nil) {
View2ViewController *two = [[View2ViewController alloc] initWithNibName:@”View2″ bundle:[NSBundle mainBundle]];
self.View2 = two;
[two release];
}
[self.navigationController pushViewController:self.View2 animated:YES];
Everything complies, and runs. When I click on the button the application does NOT display the second view. Nothing crashes, but it doesn't display the view. What am I doing wrong. I have everything linked up in Interface Builder. It's quite basic.
Is a “View-Based Application” not the correct type for doing this? Thanks everyone.