ViewControllerExercise
class ViewControllerExercise : UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDataSource, UITableViewDelegate, tableCellDelegate
Controls all UI elements within the exercise domain. This includes data entry, favouriting system and managing the exercise log.
-
Array of exercise intensity values to choose from picker view
Declaration
Swift
private let exerciseIntensity: [String] -
Instantiation of a picker view for choosing intensity of exercise
Declaration
Swift
private var exerciseIntensityPicker: UIPickerView -
Instantiation of a date picker for choosing time of exercise
Declaration
Swift
private var exerciseTimePicker: UIDatePicker -
Instantiation of a date picker for choosing duration of exercise
Declaration
Swift
private var exerciseDurationPicker: UIDatePicker -
Tracks date set by graph and hides data entry fields when not on current day using didSet
Declaration
Swift
private var currentDay: Date { get set } -
Stores an array of Exercise objects fetched from the model to display in the table
Declaration
Swift
private var loggedExercise: [Exercise] -
Tracks whether to show favourites or daily log and updates table to show that
Declaration
Swift
private var showFavouritesExercise: Bool { get set }
-
viewDidLoad override to set initial state of: Time and duration picker creation, Observer to act on current graph day changing, Observers to act based on keyboard state, Calling
updateTableDeclaration
Swift
override func viewDidLoad()
-
Updates the currentDay variable with a date provided via notification from ViewControllerGraph and re-fetches the table
Declaration
Swift
@objc private func updateDay(notification: Notification)
-
Moves exercise domain view 65 points upward
Declaration
Swift
@objc private func keyboardWillShow(sender: NSNotification) -
Moves exercise domain view to original position
Declaration
Swift
@objc private func keyboardWillHide(sender: NSNotification)
-
Initialises exercise duration picker
Declaration
Swift
private func createExerciseDurationPicker() -
Initialises Exercise Time picker
Declaration
Swift
private func createExerciseTimePicker() -
Sets number of columns for pickerView to display, here 1
Declaration
Swift
func numberOfComponents(in pickerView: UIPickerView) -> Int -
Sets number of rows for pickerView to display in each component/column, here to number of items in exerciseIntensity array
Declaration
Swift
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int -
Sets titles for each item in the row to elements of the exerciseIntensity array
Declaration
Swift
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? -
Adds the selected row’s intensity to the intensity text field
Declaration
Swift
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
-
Toggle between favourite and daily log views
Declaration
Swift
@IBAction private func toggleFavourites(_ sender: Any) -
Delegate function to toggle whether a meal is favourited
Declaration
Swift
func didPressButton(_ tag: Int)
-
Table funcion to set number of rows equal to total exercise logs
Declaration
Swift
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int -
Provides setup for table cells, setting each label
Declaration
Swift
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell -
Allows selecting a favourite to add to daily log
Declaration
Swift
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) -
Updates the table by re-fetching either a list of exercise for that day, or the user’s favourites
Declaration
Swift
private func updateTable()
-
Calls ModelController function addExercise with contents of data entry fields, if they are all filled
Declaration
Swift
@IBAction private func addExercise(_ sender: Any)
View on GitHub
ViewControllerExercise Class Reference