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

MapStack - lesson 6

leveton
March 11, 2016
33

MapStack - lesson 6

leveton

March 11, 2016
Tweet

Transcript

  1. Favoriting a location In the detail view controller, we use

    NSUserDefaults to store a location id inside an array when the user taps the favorite button.
  2. The cascading pattern NSUserDefaults gives us a quick-and-dirty way to

    store id’s, but how to inform our favorites view that a new location is favorited? The are several ways but we’ll use the cascading pattern which leverages the app delegate to propagate the change.
  3. UINavigationController We’ve seen two of the big three ways to

    handle navigation in iOS: 1) UITabbarController which handles the overall structure of our app. 2) Modal presentation which handled the details of our locations UINavigationController is the third common way to handle navigation iOS.
  4. UINavigationController For our favorites view, when a user taps a

    cell, the navigation controller will slide the detail view horizontally onto the UIWindow.
  5. UINavigationController The fact that UINavigationController is a subclass of UIViewController

    but also has a UIViewController property shouldn’t scare you. This pattern is not uncommon in cocoa.
  6. pushing controllers onto the navigation stack Here is a view

    controller being pushed onto the navigation stack. Compare this to lesson 4 when we presented view controller from the bottom as modals.
  7. Subclassing UITableViewCell When the stock table view cell isn’t good

    enough. We need our cell to have 2 label objects, 2 button objects, and an image view object.
  8. Creating our own delegates and protocols For ‘delete’ and ‘details’

    to work, we need to create our own delegate pattern. We could use cellForRowAtIndexPath like before for one button, but we would still need a delegate to handle the other button.
  9. Why are protocols confusing? Because the delegate is the servant

    and the object that owns the delegate property is the boss BUT the servant is often a superview of the boss!
  10. Why is the delegate property declaration weak? Recall that if

    it were strong, it would increment delegate’s retain count by 1. Our instance of MSTableViewCell would own the delegate. But in our favorite’s view, we’re assigning self to the delegate.
  11. Why is the delegate property declaration weak? But when we

    created the local variable ‘cell’, we’re creating a strong pointer to that cell. If the cell’s pointer to its delegate were strong, then assigning the view controller to the delegate would create a retain cycle
  12. preventing retain cycles Retain cycle cause memory leaks because the

    retain count never reaches 0 and, therefore, the memory is never deallocated.
  13. Basic networking to get locations from a server We use

    3 objects NSMutableURLRequest, NSURLSession, and NSURLSessionDataTask to get data from a server. Like other managers we’ve used, they’re just subclasses of NSObject but with extra properties and methods to facilitate interactive with a remote server.
  14. AFNetworking Using NSURL, NSMutableURLRequest, NSURLSession, and NSURLSessionDataTask by themselves, while

    powerful, are missing features that a full-fledged, network-based application may need. Many companies and indie developers use the AFNetworking 3rd-party library which uses these objects under the hood.