Delete button is automatically implemented on swipe despite not implementing trailing swipe action in tableview
Solution for this is to implement a trailing swipe action without any actions defined. code is below.
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return UISwipeActionsConfiguration.init()
}
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?
Why is the leading swipe action also duplicated as a trailing action?
Use this code to prevent trailingSwipeAction()
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle
{
return .none
}
- or
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return UISwipeActionsConfiguration(actions: [])
}
UITableViewCell, show delete button on swipe
During startup in (-viewDidLoad or in storyboard)
do:
self.tableView.allowsMultipleSelectionDuringEditing = false
Override to support conditional editing of the table view. This only needs to be implemented if you are going to be returning NO
for some items. By default, all items are editable.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
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
.
Reposition swipe-to-delete button in tableview
NO it is not possible to made any changes with delete button because it is built-in or default functionality of Apple iOS. So better to stop fighting with it :)
How to add image to delete button when we swipe on tableview cell
I solved my problem with below code but i don't know whether apple will accept or not. I have taken small UIView(100x40) in custom cell and tracking it when i swiped cell in main UIViewController. I wrote below code in "CellForRowAtIndexPath" Method and also implemented methods.
UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeGestureLeft:)];
swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[cell addGestureRecognizer:swipeGestureLeft];
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeGestureRight:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
[cell addGestureRecognizer:swipeGesture];
-(void)handleSwipeGestureLeft:(UIGestureRecognizer *)gestureRecognizer{
NSLog(@"swipe left");
self.cell.UIViewObj.hidden= Yes;
}
-(void)handleSwipeGestureRight:(UIGestureRecognizer *)gestureRecognizer{
NSLog(@"swipe reght");
CGPoint swipeLocation = [gestureRecognizer locationInView:tblView];
NSIndexPath *swipedIndexPath = [tblView indexPathForRowAtPoint:swipeLocation];
NSLog(@"swipedIndexPath %d",[swipedIndexPath row]);
self.cell = (CustomCell*)[tblView cellForRowAtIndexPath:swipedIndexPath];
self.cell.UIViewObj.hidden= No;
}
Related Topics
Nsurlsession/Nsurlconnection Http Load Failed (Kcfstreamerrordomainssl, -9802) on a Subdomain
Problems with Cropping a Uiimage in Swift
Wkwebview Decidepolicyfornavigationaction Being Call After the Long Press Recogniser Ended
How to Download and View Images from the New Firebase Storage
Xcode 11 Archive Gives Phasescriptexecution Failed
Game Exits from Pause State After Resuming It from Background in Swift
Records, Zone Doesn't Displayed in Dashboard and Delete Zone Issue Cloudkit
Swift App Crashes on Real Device But Works on Simulator
iOS Swift Flood Fill Algorithm
Navigationlink Inside Lazyvgrid Cycles All Entries on Back, Swiftui
Getting Uitableview Error "Unable to Dequeue a Cell with Identifier Cell"
Deinit Method Is Not Called in Xcode 10 Beta 6 Playground
Fbsdk (New Facebook Sdk 4.0) Implementation Is Not Working for Login with Facebook
How to Make Watchkit Extension App and My iPhone App Share the Same Icloud Databases
Retrieving Uiimage from Uiimageview in Swift
How to Position UI Elements on Background Image Relative to the Image