Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MapStack - lesson 3

leveton
March 11, 2016
44

MapStack - lesson 3

leveton

March 11, 2016
Tweet

Transcript

  1. Setting up our map You will need to add to

    key’s to your app’s info.plist These prompt the user to allow location-based services:
  2. Setting up our map We must #import <MapKit/MapKit.h>. cmd+click into

    this header to see about 3 dozen headers that make up the library We use a map, a center point for our map, a location manager to get the user’s current location, and a locations array for our data source.
  3. Setting up our map For the map - we initialize

    it with a custom frame that centers it on the device. We set showsUserLocation so that we’ll see the blue dot that tracks your movements. For the center point - we use a familiar C struct CLLocationCoordinate2D, that has two doubles - latitude and longitude
  4. Setting up our map For the location manager - we

    use a CLLocationManager object. Managers are almost always direct descendants of NSObject. They’ll have a collection of specific properties and methods For the data source - we use a mutable array (an array that can add or remove values). The array will contain custom objects that we will create. These objects will represent the various locations.
  5. Using objects to model our locations What properties should the

    location object have? 1) clearly a title 2) absolutely a 2D coordinate 3) preferably a photo 4) a distance from our location
  6. Using objects to model our locations Where can we use

    the object? Anywhere but specifically for MapStack: 1) Our map 2) To populate data for our table view cells 3) In our detail view when a user taps on a table view cell 4) In our favorites view controller for favoriting locations 5) In our global singleton (sparingly)
  7. Using objects to model our locations Why not just use

    a dictionary?? Objects can have methods that you can use to calculate things or do things specific to that object.
  8. The View Controller Lifecycle 1) init(). Be careful what code

    you put here. The view hasn’t been laid out yet. 2) set<someProperty>. In the setter, subviews are often initialized. 3) viewDidLoad. The view is loaded into memory via presentViewController or pushViewController or setViewControllers. 4) viewWillAppear. For code you want executed every time the controller is atop the window hierarchy. 5) viewWillLayoutSubviews. Typically set frames here as this gets called when the device orientation changes amongst other events (e.g. when a table is reloaded). 6) viewDidAppear. Put animation code here to ensure that the animation block fires and to ensure that the user doesn’t see the view after the animation has begun.