0

I am trying to implement a swap feature inside the uitableview, Currently my table looks like this..

enter image description here

Then i implemented these method

   func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.none
    }

    func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        swap(&groupList[sourceIndexPath.row], &groupList[destinationIndexPath.row])
        reloadData()
    }

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
            // delete item at indexPath
            print("Delete at index : \(indexPath.row)")
        }
        delete.backgroundColor = UIColor(red: 210.0/255, green: 30.0/255, blue: 75.0/255, alpha: 1.0)

        return [delete]
    }

Now it looks like this..

enter image description here

I see two white borders left and right, i want to change that background color of those borders..

also slide to delete is not working anymore (unable to slide right to left, as shown in first image)

can someone help me to fix this

Community
  • 1
  • 1
Sathya Baman
  • 3,424
  • 7
  • 44
  • 77

2 Answers2

0

Change cell editing style none to delete

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.delete
    }
user6788419
  • 7,196
  • 1
  • 16
  • 28
0

Use below code. this will work.

 func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 10
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "identuty", for: indexPath)

        return cell

    }
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
            // delete item at indexPath
            print("Delete at index : \(indexPath.row)")
        }
        delete.backgroundColor = UIColor(red: 210.0/255, green: 30.0/255, blue: 75.0/255, alpha: 1.0)

        return [delete]
    }

    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.delete
    }


    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }

enter image description here

Rishi Chaurasia
  • 520
  • 4
  • 18