簡體   English   中英

Swift tableview,SwipeAction 后重新加載Rows,無法在同一行上再次滑動

[英]Swift tableview, reloadRows after SwipeAction, unable to swipe again on the same row

我有一個帶有 swipeActions 的 tableView,這些操作調用tableView.reloadRows來更新我的表格。

我注意到我無法在操作后再次滑動剛剛更新的行。

問題是該單元格保留了該 SwipeActions 面板的統計信息。 我認為“向后滑動”這個單元格的簡單方法將解決我的問題,但我沒有找到任何方法。

(我不想重新加載整個 tableView)

func tableView(_ tableView: UITableView, 
    trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
     let removeAction = UIContextualAction(style: .normal, title: nil, handler: { _, _, _ in
        self.tableView.reloadRows(at: [indexPath], with: .automatic)
//            self.items.remove(at: indexPath.row)
//            self.tableView.deleteRows(at: [indexPath], with: .automatic)
     })
     removeAction.image = UIImage(named: "ic_garbage")!.scaleImageToFitSize(size: CGSize(width: 32.0, height: 32.0))
     removeAction.backgroundColor = UIColor.lightGray
     let actionModify = UIContextualAction(style: .normal, title: nil, handler: { _, _, _ in
        self.tableView.reloadRows(at: [indexPath], with: .automatic)
//            self.changeQty(indexPath)
     })
     actionModify.image = UIImage(named: "ic_exchange")!.scaleImageToFitSize(size: CGSize(width: 32.0, height: 32.0))
     actionModify.backgroundColor = UIColor.orange

     let toReturn = UISwipeActionsConfiguration(actions: [removeAction, actionModify])
     toReturn.performsFirstActionWithFullSwipe = false
     return toReturn
}

您需要調用完成處理程序。 你的行為應該像這樣定義......

let action = UIContextualAction(style: .normal, title: "Hello") { (action, view, completion) in
    self.doSomething()
    completion(true)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM