navigation
play

Navigation IAP 2010 iphonedev.csail.mit.edu edward benson / - PowerPoint PPT Presentation

Navigation IAP 2010 iphonedev.csail.mit.edu edward benson / eob@csail.mit.edu Wednesday, January 13, 2010 Today Programmatically Created Views Tab Bar Controllers Modal View Controllers & Tables Navigation


  1. Navigation IAP 2010 ❄ iphonedev.csail.mit.edu edward benson / eob@csail.mit.edu Wednesday, January 13, 2010

  2. Today • Programmatically Created Views • Tab Bar Controllers • Modal View Controllers & • Tables • Navigation Controllers Wednesday, January 13, 2010

  3. How many of you would pay 99c for this? Rock! Paper! Player 2 Wins! Wednesday, January 13, 2010

  4. How many of you would pay 99c for this? Wednesday, January 13, 2010

  5. How many of you would pay 99c for this? Wednesday, January 13, 2010

  6. Interface is important. Wednesday, January 13, 2010

  7. Programmatically Created Views Wednesday, January 13, 2010

  8. Name it AboutController Wednesday, January 13, 2010

  9. /* // Implement loadView to create a view // hierarchy programmatically, without using a nib. - (void)loadView { } */ Wednesday, January 13, 2010

  10. Wednesday, January 13, 2010

  11. - (void)loadView { � NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; } Wednesday, January 13, 2010

  12. - (void)loadView { � NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; � NSURLRequest *request = [NSURLRequest requestWithURL:url]; } Wednesday, January 13, 2010

  13. - (void)loadView { � NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; � NSURLRequest *request = [NSURLRequest requestWithURL:url]; � UIWebView *webView = [[UIWebView alloc] init]; } Wednesday, January 13, 2010

  14. - (void)loadView { � NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; � NSURLRequest *request = [NSURLRequest requestWithURL:url]; � UIWebView *webView = [[UIWebView alloc] init]; � [webView loadRequest:request]; } Wednesday, January 13, 2010

  15. - (void)loadView { � NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; � NSURLRequest *request = [NSURLRequest requestWithURL:url]; � UIWebView *webView = [[UIWebView alloc] init]; � [webView loadRequest:request]; � self.view = webView; } Wednesday, January 13, 2010

  16. - (void)loadView { � NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; � NSURLRequest *request = [NSURLRequest requestWithURL:url]; � UIWebView *webView = [[UIWebView alloc] init]; � [webView loadRequest:request]; � self.view = webView; � [webView release]; } Wednesday, January 13, 2010

  17. Modal Views (How do we show it?) Wednesday, January 13, 2010

  18. Modal View Controllers (we interrupt this message to bring you...) Wednesday, January 13, 2010

  19. RPSGameViewController.h - (IBAction)aboutClicked:(id)sender; RPSGameViewController.m - (IBAction)aboutClicked:(id)sender { � AboutController *ac = [[[AboutController alloc] init] autorelease]; � [self presentModalViewController:ac animated:YES]; } Now let’s wire it up in IB.. Ex3-1.zip Wednesday, January 13, 2010

  20. So how do we get rid of the modal view? .. (in a minute) Wednesday, January 13, 2010

  21. Navigation Controllers Wednesday, January 13, 2010

  22. Navigation Controllers (Push, Pop views) Wednesday, January 13, 2010

  23. RPSGameViewController.m - (IBAction)aboutClicked:(id)sender { � AboutController *ac = [[[AboutController alloc] init] autorelease]; � UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ac]; � [self presentModalViewController:nav animated:YES]; � [nav release]; } Wednesday, January 13, 2010

  24. AboutController.m -(id)init { � if (self = [super init]) { � � self.title = @"About"; � } � return self; } Wednesday, January 13, 2010

  25. AboutController.m -(id)init { � if (self = [super init]) { � � self.title = @"About"; � � � � UIBarButtonItem *dismiss = [[UIBarButtonItem alloc] init]; � � � } � return self; } Wednesday, January 13, 2010

  26. AboutController.m -(id)init { � if (self = [super init]) { � � self.title = @"About"; � � � � UIBarButtonItem *dismiss = [[UIBarButtonItem alloc] init]; � � dismiss.title = @"Dismiss"; � � � } � return self; } Wednesday, January 13, 2010

  27. AboutController.m -(id)init { � if (self = [super init]) { � � self.title = @"About"; � � � � UIBarButtonItem *dismiss = [[UIBarButtonItem alloc] init]; � � dismiss.title = @"Dismiss"; � � dismiss.target = self; � � � } � return self; } Wednesday, January 13, 2010

  28. AboutController.m -(id)init { � if (self = [super init]) { � � self.title = @"About"; � � � � UIBarButtonItem *dismiss = [[UIBarButtonItem alloc] init]; � � dismiss.title = @"Dismiss"; � � dismiss.target = self; � � dismiss.action = @selector(dismissClicked); � } � return self; } Wednesday, January 13, 2010

  29. AboutController.m -(id)init { � if (self = [super init]) { � � self.title = @"About"; � � � � UIBarButtonItem *dismiss = [[UIBarButtonItem alloc] init]; � � dismiss.title = @"Dismiss"; � � dismiss.target = self; � � dismiss.action = @selector(dismissClicked); � � self.navigationItem.leftBarButtonItem = dismiss; � � � } � return self; } Why does it crash? Wednesday, January 13, 2010

  30. AboutController.m -(void)dismissClicked { � [self dismissModalViewControllerAnimated:YES]; } What happens if we don’t put this in the .h file? Ex3-2.zip Wednesday, January 13, 2010

  31. Navigation Controllers We misused the NavigationController here. It was just an easy way to get the Navigation Bar . We’ll revisit them in a bit to see how they are really used. Wednesday, January 13, 2010

  32. Tab Bar Controllers Wednesday, January 13, 2010

  33. Tab Bars (Multiplex between views) UITabBarController Wednesday, January 13, 2010

  34. “Wrapping Controllers” We used a Navigation Controller by wrapping it around another controller [[UINavigationController alloc] initWithRootViewController:ac]; It knew what title to show because of the title property on its child controller. Wednesday, January 13, 2010

  35. Remember our app delegate - (void)applicationDidFinishLaunching:(UIApplication *)application { � // Override point for customization after app launch � gameViewController = [[RPSGameViewController alloc] init]; � [window addSubview:gameViewController.view]; � [window makeKeyAndVisible]; } To use a tab bar controller, we just “wrap” controllers in a similar way. Wednesday, January 13, 2010

  36. viewControllers An array of the root view controllers displayed by the tab bar interface. @property(nonatomic, copy) NSArray *viewControllers Wednesday, January 13, 2010

  37. In the App Delegate - (void)applicationDidFinishLaunching:(UIApplication *)application { � // Override point for customization after app launch � gameViewController = [[RPSGameViewController alloc] init]; � AboutController *a1 = [[[AboutController alloc] init] autorelease]; � AboutController *a2 = [[[AboutController alloc] init] autorelease]; � AboutController *a3 = [[[AboutController alloc] init] autorelease]; � � UITabBarController *tabs = [[UITabBarController alloc] init]; � tabs.viewControllers = [NSArray arrayWithObjects:gameViewController, a1, a2, a3, nil]; � � [window addSubview:tabs.view]; � [window makeKeyAndVisible]; } Create three AboutController instances <- Remember, at the top #import "AboutController.h" Wednesday, January 13, 2010

  38. In the App Delegate - (void)applicationDidFinishLaunching:(UIApplication *)application { � // Override point for customization after app launch � gameViewController = [[RPSGameViewController alloc] init]; � � AboutController *a1 = [[[AboutController alloc] init] autorelease]; � AboutController *a2 = [[[AboutController alloc] init] autorelease]; � AboutController *a3 = [[[AboutController alloc] init] autorelease]; � � UITabBarController *tabs = [[UITabBarController alloc] init]; � tabs.viewControllers = [NSArray arrayWithObjects:gameViewController, a1, a2, a3, nil]; � � [window addSubview:tabs.view]; � [window makeKeyAndVisible]; } Wednesday, January 13, 2010

  39. In the App Delegate - (void)applicationDidFinishLaunching:(UIApplication *)application { � // Override point for customization after app launch � gameViewController = [[RPSGameViewController alloc] init]; � � AboutController *a1 = [[[AboutController alloc] init] autorelease]; � AboutController *a2 = [[[AboutController alloc] init] autorelease]; � AboutController *a3 = [[[AboutController alloc] init] autorelease]; � � UITabBarController *tabs = [[UITabBarController alloc] init]; � tabs.viewControllers = [NSArray arrayWithObjects:gameViewController, a1, a2, a3, nil]; � � [window addSubview:tabs.view]; � [window makeKeyAndVisible]; } Wednesday, January 13, 2010

  40. Wednesday, January 13, 2010

  41. Tables Wednesday, January 13, 2010

  42. Tables (Show lists) UITableViewController Wednesday, January 13, 2010

  43. Call it GameHistory Controller Wednesday, January 13, 2010

Recommend


More recommend