- Data organization
Planets!!!!
- Create a new Xcode project. Call it Planets.
- First, let's set up our interface
- 1
UINavigationController
and 2UIViewController
- The root view controller of the
UINavigationController
should have a class ofViewController
.- The other
UIViewController
should have a class ofPlanetViewController
(you'll need to create a new class, a subclass ofUIViewController
)ViewController
should have 1UILabel
and 1UIButton
PlanetViewController
should haveUILabel
- Make sure that the
UINavigationController
is the initial view controller.
- Create an action from the button in
ViewController
to theimplementation
inViewController.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)
- The following code is boilerplate. Please read it and understand what it's doing. Copying and pasting will not work :)
- https://gist.github.com/mikekavouras/e663417c18d0e7165642
- 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 aproperty
of typeNSMutableArray
called planets- In
ViewController.m
create new instance method calledsetupPlanetData
. The return type is void and there are 0 parameters- Inside of
setupPlanetData
, initialize theplanets
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 aproperty
of typeNSMutableDicationary
called planet- In the
viewDidLoad
method inPlanetViewController.m
, set the text property of theplanetNameLabel
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 theplanet
property of thePlanetViewController
to beself.planets[0]
, the first object in theself.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 theUITableViewDelegate
didSelectRowAtIndexPath:
method orprepareForSegue
BONUS Do the exercise above in Swift