I am following the tutorial here to use a UINavigationController to switch between ViewControllers. If I download the code and follow the tutorial it works all fine and dandy, but when I try to apply this to different apps I encounter the following confusion/issue. When I am in the "FirstViewController" how do I access [self navigationController] if I do not have any navigationController in my viewController class? In this example, I cannot find out how or where the navigationController comes from in the FirstViewController. Can someone please explain how this works?
**Note: The full source code for the entire project can be found on the page I linked to above as well.
This is the line that confuses me:
[[self navigationController] pushViewController:secondViewController animated:YES];
This is the entire code for the viewController:
.h
#import <UIKit/UIKit.h>
@class SecondViewController;
@interface FirstViewController : UIViewController {
IBOutlet SecondViewController *secondViewController;
}
@property(nonatomic, retain) SecondViewController *secondViewController;
- (IBAction)PressMe:(id)sender;
@end
.m
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation FirstViewController
@synthesize secondViewController;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"First View";
}
- (IBAction)PressMe:(id)sender
{
[[self navigationController] pushViewController:secondViewController animated:YES]; //This line
}
- (void)dealloc {
[super dealloc];
}
@end