Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 3.71 KB

2015_08_13.md

File metadata and controls

66 lines (53 loc) · 3.71 KB

Objectives

  • Data organization

Exercises

Planets!!!!

  • Create a new Xcode project. Call it Planets.
  • First, let's set up our interface
    • 1 UINavigationController and 2 UIViewController
    • The root view controller of the UINavigationController should have a class of ViewController.
    • The other UIViewController should have a class of PlanetViewController (you'll need to create a new class, a subclass of UIViewController)
    • ViewController should have 1 UILabel and 1 UIButton
    • PlanetViewController should have UILabel
    • Make sure that the UINavigationController is the initial view controller. image
  • Create an action from the button in ViewController to the implementation in ViewController.m
  • Create a property called planetNameLabel in PlanetViewController.m. Make sure it's hooked up to the storyboard.

STOP!
Make sure you understand everything that just happend. IF YOU DON'T PLEASE ASK SOMEONE!

  • Next, let's set up our interaction
  • In ViewController.m, create an action when the button is tapped
  • Inside of your new action, initialize a new instance of PlanetViewController (don't forget to import the .h)
  • Run the app. When you tap the button it should navigate to the other view controller

STOP!
Make sure you understand everything that just happend. IF YOU DON'T PLEASE ASK SOMEONE!

  • Next, let's set up the data
  • In ViewController.m create a property of type NSMutableArray called planets
  • In ViewController.m create new instance method called setupPlanetData. The return type is void and there are 0 parameters
  • Inside of setupPlanetData, initialize the planets property.
  • Create an NSMutableDictionary with the following keys and values
    • @"name" : @"Saturn"
    • @"orbitalSpeed" : @(9.69)
    • @"axisTilt" : @(26.73)
  • Add the dictionary to the array
  • In viewDidLoad, call [self setupPlanetData]
  • Set a breakpoint after you call [self setupPlanetData] and inspect the values. If something is wrong, try to figure out how to fix it

STOP!
Make sure you understand everything that just happend. IF YOU DON'T PLEASE ASK SOMEONE!

  • In PlanetViewController.h create a property of type NSMutableDicationary called planet
  • In the viewDidLoad method in PlanetViewController.m, set the text property of the planetNameLabel property to [planet objectForKey:@"name"]

STOP!
Make sure you understand everything that just happend. IF YOU DON'T PLEASE ASK SOMEONE!

  • In ViewController.m, inside of your IBAction (the action for your button), set the planet property of the PlanetViewController to be self.planets[0], the first object in the self.planets property.
  • Run your app. Is it working? If no, set some breakpoints and add some NSLogs until you find out what's

Next Steps

  • Add a few more labels to PlanetViewController so that you can display the orbitalSpeed and the axisTilt
  • REFACTOR THE CODE TO USE A PLANET CLASS INSTEAD OF NSDICTIONARY
  • Add more planets

Next Next Steps

  • Change ViewController to a table that displays all of the planets in your planets property.
  • Pass information to PlanetViewController either by using the UITableViewDelegate didSelectRowAtIndexPath: method or prepareForSegue

BONUS Do the exercise above in Swift