PreferencesTableViewController

class PreferencesTableViewController : UITableViewController, UINavigationBarDelegate, UIDocumentPickerDelegate

There are two preferences available:

  • use or not cache
  • select the map source (tile server)

Preferences are kept on UserDefaults with the keys kDefaultKeyTileServerInt (Int) and kDefaultUseCache` (Bool)

Table view data source

  • Returns 4 sections: Units, Cache, Map Source, Activity Type

    Declaration

    Swift

    override func numberOfSections(in tableView: UITableView?) -> Int
  • Returns the title of the existing sections. Uses kCacheSection, kUnitsSection, kMapSourceSection and kActivityTypeSection for deciding which is the section title

    Declaration

    Swift

    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
  • For section kCacheSection returns 2, for kUnitsSection returns 1, for kMapSourceSection returns the number of tile servers defined in GPXTileServer, and for kActivityTypeSection returns CLActivityType.count

    Declaration

    Swift

    override func tableView(_ tableView: UITableView?, numberOfRowsInSection section: Int) -> Int
  • For kCacheSection:

    1. If indexPath.row is equal to kUserOfflineCacheCell, returns a cell with a checkmark
    2. If indexPath.row is equal to kClearCacheCell, returns a cell with a red text kClearCacheCell

    If the section is kMapSourceSection, it returns a chekmark cell with the name of the tile server in the indexPath.row index in GPXTileServer. The cell is marked if selectedTileServerInt is the same as indexPath.row.

    If the section is kActivityTypeSection it returns a checkmark cell with the name and description of the CLActivityType whose indexPath.row matches with the activity type.

    Declaration

    Swift

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
  • Performs the following actions depending on the section and row selected: If the cell kUseImperialUnitCell in kUnitsSectionit sets or unsets the use of imperial units (useImperial in Preferencesand calls the delegate methoddidUpdateUseImperial`.

    If a cell in kCacheSection is selected and the cell is 1. kUseOfflineCacheCell: Activates or desactivates the useCache in Preferences, and calls the delegate method didUpdateUseCache 2. KClearCacheCacheCell: Clears the current cache and calls

    If a cell in kMapSourceSection is selected: Updates tileServerInt in Preferences and calls the delegate method didUpdateTileServer

    If a cell in kActivitySection is selected: Updates the activityType in Preferences and calls the delegate method didUpdateActivityType.

    In each case checks or unchecks the corresponding cell in the UI.

    Declaration

    Swift

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

UIDocumentPickerDelegate