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)
-
Delegate for this table view controller.
Declaration
Swift
weak var delegate: PreferencesTableViewControllerDelegate?
-
Global Preferences
Declaration
Swift
var preferences: Preferences
-
Declaration
Swift
var cache: MapCache
-
Store cached size for reuse.
Declaration
Swift
var cachedSize: String
-
Does the following:
- Defines the areas for navBar and the Table view
- Sets the title
- Loads the Preferences from defaults
Declaration
Swift
override func viewDidLoad()
-
Close this controller.
Declaration
Swift
@objc func closePreferencesTableViewController()
-
Loads data
Declaration
Swift
override func viewDidAppear(_ animated: Bool)
-
Does nothing for now.
Declaration
Swift
override func didReceiveMemoryWarning()
-
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
andkActivityTypeSection
for deciding which is the section titleDeclaration
Swift
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
-
For section
kCacheSection
returns 2, forkUnitsSection
returns 1, forkMapSourceSection
returns the number of tile servers defined inGPXTileServer
, and for kActivityTypeSection returnsCLActivityType.count
Declaration
Swift
override func tableView(_ tableView: UITableView?, numberOfRowsInSection section: Int) -> Int
-
For
kCacheSection
:- If
indexPath.row
is equal tokUserOfflineCacheCell
, returns a cell with a checkmark - If
indexPath.row
is equal tokClearCacheCell
, returns a cell with a red textkClearCacheCell
If the section is kMapSourceSection, it returns a chekmark cell with the name of the tile server in the
indexPath.row
index inGPXTileServer
. The cell is marked ifselectedTileServerInt
is the same asindexPath.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
- If
-
Performs the following actions depending on the section and row selected: If the cell
kUseImperialUnitCell
inkUnitsSection
it sets or unsets the use of imperial units (useImperial
inPreferences
and calls the delegate method
didUpdateUseImperial`.If a cell in kCacheSection is selected and the cell is 1. kUseOfflineCacheCell: Activates or desactivates the
useCache
inPreferences
, and calls the delegate methoddidUpdateUseCache
2. KClearCacheCacheCell: Clears the current cache and callsIf a cell in
kMapSourceSection
is selected: UpdatestileServerInt
inPreferences
and calls the delegate methoddidUpdateTileServer
If a cell in
kActivitySection
is selected: Updates theactivityType
inPreferences
and calls the delegate methoddidUpdateActivityType
.In each case checks or unchecks the corresponding cell in the UI.
Declaration
Swift
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
-
Declaration
Swift
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])