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
iOS - Could Not Open Obj File When Convert Mdlasset to Mdlmesh
Issues While Lightweight Core Data Migration
Swift Spritekit Get Visible Frame Size
Call Function on App Termination in Swift
How to Get Section of UItableview from Inside a Child UIcollectionview
How to Store Data from a Picker View in a Variable When a Button Is Pressed
Calling Asynchronous Method Inside For-Loop
Realm Data Insertion Took Over 7Mins for Big Size JSON
Swift - Rotate Gesture and Rotation Increments of 90 Degrees
Having Trouble with Musickit Sample App Provided by Apple
How to Get Data to Return from Nsurlsessiondatatask in Swift
Performance Issue with Swiftui List
Overlaying Image on Video Reduces Video Resolution
Cocos2D Fcm Push Notification Not Working
Swift Corebluetooth Reading a Float Array from Ble
Swift 3/iOS 10/Todayextension - Userdefaults Always Returns Nil