简体   繁体   中英

How I can reload tableview data after the animation of fade swipeAction completed

I use SwipeCellKit for do swipe actions for my tableview. I try to do the left swipe for check or unckech for accessoryType of my cell and everything work fine, but after i press check the tableview reload the data immediatelly and i can't see the animation of roollback the check button. So i want to ask how i can call reload data after this animation end.

I have something like this:

I have something like this:

But i want fade animation like this

I want this animation

My code:

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
    var action = super.tableView(tableView, editActionsForRowAt: indexPath, for: orientation) ?? []

    guard orientation == .left else { return action }

    let checkAction = SwipeAction(style: .destructive, title: nil) { action, indexPath in     

        self.completeItem(at: indexPath)

    }
    action.append(checkAction)
    return action

}



private func completeItem(at indexPath: IndexPath){
    if let item = itemArray?[indexPath.row]{

        do{
            try realm.write {
                item.done = !item.done
            }

        }

        catch{

            print( error.localizedDescription)

        }
    }
    tableView.reloadData()

}

In order to hide the action on select, you need to set the hidesWhenSelected property for the action.

checkAction.hidesWhenSelected = true

Also, the example doesn't reload the tableView. Instead, they use an animation to remove the dot. You will need to manually delay your reload until the hide animation is complete.

See line 156 for the property

See lines 256 - 273 for the animation https://github.com/SwipeCellKit/SwipeCellKit/blob/develop/Example/MailExample/MailTableViewController.swift

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM