Delete Button Is Automatically Implemented on Swipe Despite Not Implementing Trailing Swipe Action in Tableview

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



Leave a reply



Submit