1 / 19

EEC-492/693/793 iPhone Application Development

EEC-492/693/793 iPhone Application Development. Lecture 11 Wenbing Zhao & Nigamanth Sridhar. Outline. Administrative From now on: review your app/progress at the end of each session Navigation Controller Assignments: The push and pop app Continue b uild ing the calculator app.

rodneyj
Download Presentation

EEC-492/693/793 iPhone Application Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EEC-492/693/793iPhone Application Development Lecture 11 Wenbing Zhao & Nigamanth Sridhar EEC492/693/793 - iPhone Application Development

  2. Outline Administrative From now on: review your app/progress at the end of each session Navigation Controller Assignments: The push and pop app Continue building the calculator app 12/20/2019 2 EEC492/693/793 - iPhone Application Development EEC492/693/793 - iPhone Application Development

  3. Navigation Controller • The navigation controller (UINavigationController) can be used to manage a stack of view controllers • Stack: a data structure that manages a collection of objects • last in, first out / first in, last out • Push: add an object to a stack • Pop: remove an object from the stack • Navigation bar • Title of the top view controller • Left bar button to go to the previous view controller (pop) • Right bar button to allow editing etc. EEC492/693/793 - iPhone Application Development

  4. Example App: Mail Top view controller’s title Previous view controller’s title Top view controller’s view Top view controller’s toolbar EEC492/693/793 - iPhone Application Development

  5. How to Navigate • Push to add a view controller (to the UINavigationController’s stack) • - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; • Pop to remove a view controller from the stack (the previous one will become the top view controller) • - (UIViewController *)popViewControllerAnimated:(BOOL)animated; • Set to change the entire stack of view controllers • - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated; EEC492/693/793 - iPhone Application Development

  6. Pushing Your First View Controller - (void)applicationDidFinishLaunching { // Create a navigation controller navController = [[UINavigationController alloc] init]; // Push the first view controller on the stack [navController pushViewController:firstViewController animated:NO]; // Add the navigation controller’s view to the window [window addSubview:navController.view]; …. } EEC492/693/793 - iPhone Application Development

  7. Push from within a View Controller on the Stack due to User Actions - (void)someAction:(id)sender { // Potentially create another view controller UIViewController *viewController = ...; [self.navigationController pushViewController:viewController animated:YES]; } • Where on earth does navigationController come from?! • It is defined in UIViewController as a property • Since our view controller inherited from UIViewController, we do have it as well • navigationItem is another property declared in UIViewController EEC492/693/793 - iPhone Application Development

  8. Customizing Navigation • UINavigationItem: Describes appearance of the navigation bar • Title string or custom title view • Left & right bar buttons • More properties defined in UINavigationBar.h • Every view controller has a navigation item for customizing • Displayed when view controller is on top of the stack Left Bar Button Item Navigation Item View Controller Title View Right Bar Button Item EEC492/693/793 - iPhone Application Development

  9. Displaying a Title • UIViewController already has a title property • @property(nonatomic,copy) NSString *title; • Navigation item inherits automatically • Previous view controller’s title is displayed in back button viewController.title = @“Detail”; EEC492/693/793 - iPhone Application Development

  10. Left & Right Buttons • UIBarButtonItem • Special object, defines appearance & behavior for items in navigation bars and toolbars • Display a string, image or predefined system item • Target + action (like a regular button) EEC492/693/793 - iPhone Application Development

  11. Text Bar Button Item - (void)viewDidLoad { UIBarButtonItem *fooButton = [[UIBarButtonItem alloc] initWithTitle:@"Foo” style:UIBarButtonItemStyleBordered target:self action:@selector(foo:)]; self.navigationItem.leftBarButtonItem = fooButton; [fooButton release]; } EEC492/693/793 - iPhone Application Development

  12. System Bar Button Item - (void)viewDidLoad { UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)]; self.navigationItem.rightBarButtonItem = addButton; [addButton release]; } EEC492/693/793 - iPhone Application Development

  13. Edit/Done Button • Very common pattern • Every view controller has one available • Target/action already set up self.navigationItem.leftBarButtonItem = self.editButtonItem; // Called when the user toggles the edit/done button - (void)setEditing:(BOOL)editing animated:(BOOL)animated { // Update appearance of views } EEC492/693/793 - iPhone Application Development

  14. Custom Title View • Arbitrary view in place of the title UISegmentedControl *segmentedControl = ... self.navigationItem.titleView = segmentedControl; [segmentedControl release]; EEC492/693/793 - iPhone Application Development

  15. Back Button • If you don’t like the default back button (using the title of the view controller), you can customize it self.title = @“Hello there, CS193P!”; UIBarButtonItem *heyButton = [[UIBarButtonItem alloc] initWithTitle:@“Hey!” ...]; self.navigationItem.backButtonItem = heyButton; [heyButton release]; EEC492/693/793 - iPhone Application Development

  16. Combining Tab Bar and Navigation Controllers • You can combine the tab bar and navigation controllers to create multiple parallel hierarchies EEC492/693/793 - iPhone Application Development

  17. Tab Bar + Navigation Controllers View Controller Navigation Item View Controller Navigation Item View Controller View Controller View Controller Navigation Item EEC492/693/793 - iPhone Application Development

  18. Nesting Navigation Controllers (into Tab Bar Controller) • Create a tab bar controller tabBarController = [[UITabBarController alloc] init]; • Create each navigation controller navController = [[UINavigationController alloc] init]; [navController pushViewController:firstViewController animated:NO]; • Add them to the tab bar controller tabBarController.viewControllers = [NSArray arrayWithObjects: navController, anotherNavController, someViewController, nil]; EEC492/693/793 - iPhone Application Development

  19. Assignment: Push and Pop App EEC492/693/793 - iPhone Application Development

More Related