How do I disable the full swipe on a tableview cell in iOS11

前端 未结 2 502
小鲜肉
小鲜肉 2020-12-31 03:54

UITableViewDelegate.h

// Swipe actions
// These methods supersede -editActionsForRowAtIndexPath: if implemented
// return nil to get the default swipe actio         


        
2条回答
  •  感动是毒
    2020-12-31 04:23

    Implement like below :

    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, sourceView, completionHandler) in
            print("index path of delete: \(indexPath)")
            completionHandler(true)
        }
        let swipeAction = UISwipeActionsConfiguration(actions: [delete])
        swipeAction.performsFirstActionWithFullSwipe = false // This is the line which disables full swipe
        return swipeAction
    }
    

    This is the line which disables full swipe

    swipeAction.performsFirstActionWithFullSwipe = false 
    

    And remove the other functions if you implement any like editingStyle and editActionsForRowAt.

提交回复
热议问题