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

前端 未结 2 493
小鲜肉
小鲜肉 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.

    0 讨论(0)
  • I was able to disable swipe actions for particular cells by following this answer: https://stackoverflow.com/a/50597672/1072262

    Instead of returning nil you can return:

    return UISwipeActionsConfiguration.init()
    
    0 讨论(0)
提交回复
热议问题