- Build an iphone application
- Write the code you care about
- Extend in the future
Focus on data
One thing at a time
Screenfuls of content
navigation bar vs tab bar
navigation bar
hierarchy of content
drill down into great detail
tab-bar
self-contained modes
A Screenful of contents
slice of your application
views, data, logic
self-contained controller
List Controller --> Detail Controller --> Photo Contoller
View Controllers in Interface Builder(storyboard)
lay out a view in interface builder
View controller is file's owner
hook up view outlet
create with -initWithNibName:bundle:
the second way:
View Controller in Code
override -loadview
create your views
set the view property
//subclass of UIViewController- (void) loadView{ MyView *myView = [[MyView alloc] initWithFrame:frame]; [self setView:myView]; [myView release];}
Hooks for Interesting Events
- Appear
Load your data
- Disappear
Save your data
- Interface rotation
- Memory warnings
link view controller together
UINavigationController
manager a stack of view controllers
navigation bar
Top view controller's view
Top view controller's title
Previous view controller't title (back bar item)
Modifying the navigation stack
adding a view controller
-pushViewController:animated:
remove
-popViewControllerAnimated:
setting up navigation
create
navigationController = [[UINavigationController alloc] init];
push the root view controller
[navigationController pushViewController:firstViewController animated:NO];
add its view to window
[window addSubView:navigationController.view];
Navigating
push from within a view controller on the stack
[self.navigationController pushViewController:anotherViewController animated:YES];
rarely call pop directly
Automatically invoked by the back button
Subclass UIViewController for each screenful
Set up in -applicationDidFinishLaunching
Push View controllers
TabBar
@implementation TabBarDemoDelegate- (void) applicationDidFinishLaunching:(UIApplication *) application{ [window addSubView:tabBarController.view]; [window makeKeyAndVisible];}
Autoresizing your views programatically, or spring and struts
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
image
imageView.contentMode = UIViewContentModeScaleAspectFit;imageView.backgroundColor = [UIColor blackColor];