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

MapSwift - lesson 11

leveton
June 11, 2017
24

MapSwift - lesson 11

leveton

June 11, 2017
Tweet

Transcript

  1. Inserting and deleting rows on a table view Let’s refactor

    deleteButtonTappedFrom(cell: location:) in favorites controller for a much better user experience. Everything in between beginUpdates and endUpdates is animated. Here we animate the removing of a cell from our table.
  2. Inserting and deleting rows on a table view Use caution

    when adding/deleting rows yourself. beginUpdates and endUpdates trigger some dataSource delegate methods. But other critical methods like cellForRowAtIndexPath are not called. Because of this, we must force the table to reload. If you don’t call reloadData, you’ll crash when removing the last cell.
  3. Inserting and deleting rows on a table view We must

    call reload data in a block. Calling it immediately will preempt the row animation. This is also a good place to notify the settings controller as we’re sure that the datasource is updated.
  4. Implementing the Settings Controller We will allow users to configure

    3 settings in a grouped table view 1) Set app theme color 2) Set the range of distances to show on our map and locations table 3) Move cells to order the types on our favorites table This will be our most complicated controller and the culmination of everything we’ve learned.
  5. Grouped table views So far we’ve used only the default

    table view setup. For favorites we’ll set the table to UITableViewStyleGrouped and use the section property of our indexPaths to organize different groups for each setting. Your phone’s Settings app is the most familiar example of a grouped table layout.
  6. MVC Look at the project navigator, we’ve created groups to

    better organize our file system. Model-View-Controller architecture fits nicely with the idea of our UIViewControllers as places to implement business logic - getting the model data presented on to the views. MVC is old and many iOS devs prefer a Model-View-ViewModel architecture where the business logic lives in a separate manager class that the UIViewController talks to.
  7. MVC For MapStack.. Models - MSLocation is the only one

    we used but a typical app will have several including a ‘user’ model. Views - subclasses of UIView e.g. buttons, table view cells, MKMapView, image views, labels, etc. View Controllers - persists data to the views. Controls and owns the views as well as its ‘view’ property that has been our canvas throughout.
  8. Coming full circle - the app delegate This should make

    more sense now that we’ve worked with delegates and protocols. Press your device’s home button or, on the simulator, go to Hardware > Home. applicationDidEnterBackground() here we may want to notify any networking to cancel or to save any unsaved input.