ViewControllerFood

class ViewControllerFood : UIViewController, UIPickerViewDelegate, UITableViewDataSource, UITableViewDelegate, tableCellDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate

Controls all UI elements within the food domain. This includes data entry, favouriting system and managing the food log.

  • Instantiation of a date picker for choosing time of meal

    Declaration

    Swift

    private var foodTimePicker: 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 Meals objects fetched from the model to display in the table

    Declaration

    Swift

    private var loggedMeals: [Meals]
  • Stores index of selected cell to allow expanding to show more info when selected

    Declaration

    Swift

    private var selectedCellIndexPath: [IndexPath?]
  • Height for a cell which has been selected and expanded

    Declaration

    Swift

    private let selectedCellHeight: CGFloat
  • Height for an unselected and contracted cell

    Declaration

    Swift

    private let unselectedCellHeight: CGFloat
  • Tracks whether to show favourites or daily log and updates table to show that

    Declaration

    Swift

    private var showFavouritesFood: Bool { get set }
  • viewDidLoad override to set initial state of: TimePicker creation, Observer to act on current graph day changing, Observers to act based on keyboard state, Calling updateTable

    Declaration

    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 food domain view 65 points upward

    Declaration

    Swift

    @objc
    func keyboardWillShow(sender: NSNotification)
  • Moves food domain view to original position

    Declaration

    Swift

    @objc
    func keyboardWillHide(sender: NSNotification)
  • 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 meals

    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 if showing favourites, else toggles expanding of cell

    Declaration

    Swift

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
  • Allows expanding of cells by changing cell height for specific rows

    Declaration

    Swift

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
  • Updates the table by re-fetching either a list of meals for that day, or the user’s favourites

    Declaration

    Swift

    private func updateTable()
  • Calls ModelController function addMeal with contents of data entry fields, if they are all filled

    Declaration

    Swift

    @IBAction
    private func addFoodToLog(_ sender: Any)