0

I'm new to objective-c and gotten some legacy code for adding new features. My app needs that rows from a table are deleted by swiping then out. The implementation already support the ordering of rows.

I have already read previous questions UITableViewCell, show delete button on swipe and using swipe gesture to delete row on tableview. I don't want to show any button for deleting rows( nor the (-) (red left button) neither the DELETE button that is displayed on the right when clicking the (-) red left button ).

I have already defined the following methods:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"editingStyleForRowAtIndexPath");
    return UITableViewCellEditingStyleNone;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"canEditRowAtIndexPath");
    return YES; // allow that row to swipe
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"commitEditingStyle");
}

The behavior is that with this "configuration" the delete left red button is displayed. When it is clicked, it displays a DELETE button on the right of the row. Clicking on it run the commitEditingStyle delegate.

Removing the tableView:editingStyleForRowAtIndexPath make disappear the left red button and swipe does not work. Nor I manage to get execution in the commitEditingStyle delegate.

Any suggestion or ideas why the commitEditingStyle delegate is not invoked?

Community
  • 1
  • 1
kitimenpolku
  • 2,604
  • 4
  • 36
  • 51
  • 1
    why the delete button appears is for getting double-confirmation from the uses whether they really like to delete the row (e.i. destructive procedure). that is a standard build-in feature of delete-procedure. you can always add a _custom_ swipe-gesture recognizer to your each cell and that custom gesture recognizer can trigger a direct delete on your rows without the extra confirmation. – holex Feb 26 '15 at 10:13
  • Is that the only way to do it? There is no way to avoid the double-confirmation? When people talk about *swipe-to-delete* they mean swipe-to-display the confirmation delete button? http://stackoverflow.com/questions/3309484/uitableviewcell-show-delete-button-on-swipe answer 2 and 3 seems to be referring to swipe for deleting... Maybe I'm understanding those wrong? – kitimenpolku Feb 26 '15 at 10:19
  • 1
    you will need to create your own custom cell and add to it some gesture recogniser and then simulate the same affect of delete button with animation. For Instance: https://github.com/mbigatti/BMXSwipableCell – Mike.R Feb 26 '15 at 10:21
  • 2
    @kitimenpolku, that is a 5 years old answer (probably for iOS3...), I would not rely on that; implementing a custom swipe-gesture recognizer for your cells will do the job for you. – holex Feb 26 '15 at 10:23
  • Yep, I have already my custom cell defined. I will take a look to it. Kiitos! – kitimenpolku Feb 26 '15 at 10:26
  • @kitimenpolku- did you get this working? I need same functionality. i.e. delete a complete row on swipe directly . Without showing any delete option. – ARS Nov 03 '17 at 04:51
  • @ARS unfortunately this is a quite old question. Based on the comments I solved this issue some time ago. It might help https://stackoverflow.com/questions/21197266/swipe-to-delete-row-without-having-to-hit-the-delete-button – kitimenpolku Nov 03 '17 at 09:17

2 Answers2

0

Just write code for deleting row in to - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

I have checked and this works fine for me.

This will delete row on swipe without showing delete button. I hope this will solve your problem.

Dharmesh Vaghani
  • 718
  • 6
  • 23
  • As I understand from the docs, it should return "The editing style of the cell for the row identified by indexPath.". It's in the "commitEditingStyle" data source method where it should happen that. From the commitEditingStyle docs: "Asks the data source to commit the insertion or deletion of a specified row in the receiver.". In this way, you are breaking the architecture for which it was designed. Dont know yet how good is that. Dont have enough experience to declare this as the right answer. – kitimenpolku Feb 26 '15 at 10:41
  • 1
    commitEditingStyle will call only when you will tap on the button which appears after swipe. If you perform any action before returning editting style then this will not break any structure. – Dharmesh Vaghani Feb 26 '15 at 11:02
-3

replace

return UITableViewCellEditingStyleNone 

with

return UITableViewCellEditingStyleDelete
tkanzakic
  • 5,499
  • 16
  • 34
  • 41
Alexandr Kolesnik
  • 1,929
  • 1
  • 17
  • 30