0

I'm creating a program that allows swiping of a row to colour it in.

I have the below function for handling this.

 func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
       if multipleActive
       {
           let select = UITableViewRowAction(style: .normal, title: "Received") { action, index in
               print("Row Selected")
               let cell = tableView.cellForRow(at: index)
               let rowInt : Int = index.row
               cell?.backgroundColor = .green
           }
           select.backgroundColor = .green


           let deselect = UITableViewRowAction(style: .normal, title: "Deselect") { action, index in
               print("Unpicked")
               let cell = tableView.cellForRow(at: index)
               let rowInt : Int = index.row
               cell?.backgroundColor = .none
           }
           deselect.backgroundColor = .blue

           return [select, deselect]
       }
       else {
           return nil
       }

   }

However, I have a cancel button and on cancel I want the rows in the table to have the colouring set back to white. Is there a function that exists already for this?

Also I can swipe the rows and when multipleActive is set to false it will show the delete button. I don't want swiping to be possible if multipleActive is not true.

Rashed
  • 2,349
  • 11
  • 26
benjiiiii
  • 478
  • 10
  • 33
  • Do you create model or array of Data? If yes then maintain color status each time there reload tableview for each activity. – Manish Mahajan Apr 17 '18 at 09:55
  • Please check https://stackoverflow.com/questions/46414707/how-do-i-disable-the-full-swipe-on-a-tableview-cell-in-ios11/46417015#46417015 – Vini App Apr 17 '18 at 11:08
  • That's a different question. They want to disable the full swiping method. I just want the option of delete to not be there. – benjiiiii Apr 17 '18 at 11:14

0 Answers0