From ae52f996f2b714e6b27d409af42dfdd30c0fbcd5 Mon Sep 17 00:00:00 2001 From: Deborah Engelmeyer Date: Mon, 6 Nov 2017 09:37:05 -0800 Subject: [PATCH] Add edit of interval phases --- Trainer/IntervalsViewController.swift | 19 ++++++++++--------- Trainer/PhasesViewController.swift | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Trainer/IntervalsViewController.swift b/Trainer/IntervalsViewController.swift index 8b91192..10e0f05 100644 --- a/Trainer/IntervalsViewController.swift +++ b/Trainer/IntervalsViewController.swift @@ -32,7 +32,7 @@ class IntervalsViewController: UITableViewController { // self.clearsSelectionOnViewWillAppear = false // Uncomment the following line to display an Edit button in the navigation bar for this view controller. - // self.navigationItem.rightBarButtonItem = self.editButtonItem + self.navigationItem.rightBarButtonItem = self.editButtonItem } override func didReceiveMemoryWarning() { @@ -102,25 +102,26 @@ class IntervalsViewController: UITableViewController { } } - /* - // Override to support conditional editing of the table view. + // Allow editing of the table view for the phase section only override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { // Return false if you do not want the specified item to be editable. - return true + return indexPath.section == phaseSection } - */ - /* - // Override to support editing the table view. + + // Delete phases from the intervals override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { // Delete the row from the data source - tableView.deleteRows(at: [indexPath], with: .fade) + if let phase = intervals.phases?[indexPath.row] as? Phase { + if DataAccess.delete(phase) { + tableView.deleteRows(at: [indexPath], with: .fade) + } + } } else if editingStyle == .insert { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } - */ /* // Override to support rearranging the table view. diff --git a/Trainer/PhasesViewController.swift b/Trainer/PhasesViewController.swift index 1f19aed..8328fbf 100644 --- a/Trainer/PhasesViewController.swift +++ b/Trainer/PhasesViewController.swift @@ -137,7 +137,6 @@ class PhasesViewController: UITableViewController { // Delete the row from the data source if let phase = workout.phases?[indexPath.row] as? Phase { if DataAccess.delete(phase) { - //tableView.reloadSections(IndexSet([phasesSection]), with: .automatic) tableView.deleteRows(at: [indexPath], with: .fade) } }