So I am creating an alarm clock. One view controller is a table view. The other view controller consists of a UIDatePicker with a submit button. The goal is that when the user clicks the submit button, it saves the date on the date picker. As well as saving the date, it is a segue to the table view controller. I am trying to display the time saved as the label in the cell.
This is my code for the DatePicker view controller. I defined the variable outside of the function. Then when they click submit it should update the value. However it does not update it when it passes through the segue.
var myDate = "1:39 PM" @IBAction func submitDate(_ sender: AnyObject) { myDate = DateFormatter.localizedString(from: dateOutlet.date, dateStyle: DateFormatter.Style.none, timeStyle: DateFormatter.Style.short) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "save" { let toViewController = segue.destination as! TableViewController toViewController.myDate = myDate } }
This is my code for the table view controller. When i click submit, it does not show the label as the time chosen in the DatePicker. It shows "1: 39 PM." Which was what I initially defined it as.
var myDate = "0" override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = Bundle.main.loadNibNamed("TableViewCell", owner: self, options: nil)?.first as! TableViewCell cell.textLabel?.text = myDate return cell }