Deepak Sharma
Deepak Sharma

Reputation: 6537

UITableView multiple actions

In the editing mode of UITableView, I need three things, the first two are easy to get using UITableView delegate methods:

  1. Delete (- in red) button on the left of the row,

  2. Reorder (three bars) row button on the right of the row,

  3. A custom defined action (with title & background color) appearing on the left side of reorder (three bars) button.

How is it possible to get these three actions together?

Upvotes: 0

Views: 352

Answers (1)

MUKUL BAKSHI
MUKUL BAKSHI

Reputation: 11

Hi yes it is possible to make or add your own custom action by implementing the tableView delegate

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

 let archiveAction:UITableViewRowAction = UITableViewRowAction(style: .default, title: "                      ") { (rowAct, index) in

   }

 let deleteAction:UITableViewRowAction = UITableViewRowAction(style: .default, title: "                     ") { (rowAct, index) in

}

   let archiveImg = UIImageView(image: UIImage(named: "archive_btn"))
        archiveImg.contentMode = .scaleAspectFit
        archiveAction.backgroundColor = UIColor(patternImage:archiveImg.image!)

        let deleteImg = UIImageView(image: UIImage(named: "delete_btn"))
        deleteImg.contentMode = .scaleAspectFit
        deleteAction.backgroundColor = UIColor(patternImage:deleteImg.image!)

        return [deleteAction,archiveAction]
}

Upvotes: 1

Related Questions