- (void)viewDidLoad {
[super viewDidLoad];
UIViewController *one = [[[UIViewController alloc] init] autorelease];
[one.view setBackgroundColor:[UIColor yellowColor]];
[one setTitle:@"One"];
navController = [[UINavigationController alloc] initWithRootViewController:one];
// here 's the key to the whole thing: we're adding the navController's view to the
// self.view, NOT the one.view! So one would be the home page of the app (or something)
[self.view addSubview:navController.view];
one = [[[UIViewController alloc] init] autorelease];
[one.view setBackgroundColor:[UIColor blueColor]];
[one setTitle:@"Two"];
// subsequent views get pushed, pulled, prodded, etc.
[navController pushViewController:one animated:YES];
}
Dan Rosenstark, Author of MIDI Designer, muses about all things tech. Particularly: Notes on software development in Swift, Objective-C, and many non-Apple languages. Also: lots of random technology notes on OS X and iOS.
Twitter | LinkedIn | Stack Overflow
Sunday, June 20, 2010
World's Simplest Example: UINavigationController
This is a Simplest Example of how to use a UINavigationController (based on my question here). The idea is that the example is 100% self contained. Warning: if you actually code this way (big monolithic classes) your code will suck. In this example, the UIViewControllers should actually be subclasses that contain the behavior and data they need to do their work. But that's another problem.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment