Disable Cell Swipe Action

Disable Cell Swipe Action

I think the method you're looking for is tableView(_:canEditRowAtIndexPath:).

Returning false in this method should disable the swipe action. You can then tie this value to your search controller:

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return !searchController.active
}

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

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.

UITableView disable swipe to delete for particular cells swift

You might customize the UITableViewDelegate's function editingStyleForRowAt, especially returning UITableViewCellEditingStyle.none when you don't need the swipe, something like:

public func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle
{
if mainList[indexPath.row].statusId == "12" {
return UITableViewCellEditingStyle.none
} else {
return UITableViewCellEditingStyle.delete
}
}

Disable to swipe cell in tableView if condition is false in swift?

You need to use canEditRowAt for that and return Bool value according to your condition.

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {

if condition == true {
return true
}
return false
}

No need check condition in editActionsForRowAtIndexPath method.

iOS - disable right or left swipe for UITableViewCell

Try to return the empty array of actions in trailingSwipeActionsConfigurationForRowAt method to disable one sided action.

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let swipeAction = UISwipeActionsConfiguration(actions: [])

return swipeAction
}

How do I disable the default Delete swipe action and display my custom swipe action instead?

Based on ChillY's answer to this question (Why is the leading swipe action also duplicated as a trailing action?), I realized the problem was that I was returning nil instead of UISwipeActionsConfiguration(actions: []).

Now I just have to figure out why the swipes are not disappearing after the action has been executed. Any ideas?

How to disable delete action on UITableViewCell?

Try this

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return false
}

Edit

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let swipeAction = UISwipeActionsConfiguration(actions: [])
swipeAction.performsFirstActionWithFullSwipe = false // This is the line which disables full swipe
return swipeAction
}

How to prevent cells from indenting when using custom swipe actions in edit mode?

This method seems to work! tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool
https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614873-tableview?language=objc



Related Topics



Leave a reply



Submit