简体   繁体   English

淡入淡出的swipeAction动画完成后如何重新加载tableview数据

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

I use SwipeCellKit for do swipe actions for my tableview. 我使用SwipeCellKit为我的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. 我尝试对单元格的annexType进行向左滑动检查或松开,并且一切正常,但是在我按下检查后,tableview立即重新加载了数据,并且我看不到roollback动画检查按钮。 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. 为了在选择时隐藏动作,您需要为动作设置hidesWhenSelected属性。

checkAction.hidesWhenSelected = true

Also, the example doesn't reload the tableView. 另外,该示例不会重新加载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 有关属性,请参见第156行

See lines 256 - 273 for the animation https://github.com/SwipeCellKit/SwipeCellKit/blob/develop/Example/MailExample/MailTableViewController.swift 动画请参见第256-273行https://github.com/SwipeCellKit/SwipeCellKit/blob/develop/Example/MailExample/MailTableViewController.swift

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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