有没有办法将单元格向左/向右拖动然后释放后将单元格移回初始位置?

时间:2018-01-12 21:11:36

标签: ios swift uitableview

我已经为UITableViewCell实现左/右滑动

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
       let closeAction = UIContextualAction(style: .normal, title:  "Close", handler: { (ac:UIContextualAction, view: UIView, success:(Bool) -> Void) in
        success(true)
    })

    closeAction.image = UIImage(named: "tick")
    closeAction.backgroundColor = .purple
    let config = UISwipeActionsConfiguration(actions: [closeAction])

    return config
}



override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let modifyAction = UIContextualAction(style: .normal, title:  "Update", handler: { (ac:UIContextualAction, view: UIView, success:(Bool) -> Void) in
        print("Update action ...")

        success(true)
    })

    modifyAction.image = UIImage(named: "hammer")
    modifyAction.backgroundColor = .blue

    return UISwipeActionsConfiguration(actions: [modifyAction])
}

但是当我拖动一些东西后释放它时,单元格仍保留在最后一个位置(当我再次点击它时,它会向后移动)。有没有办法在将它拖动一些并释放后将单元移回初始位置?感谢

0 个答案:

没有答案