Swipe to delete not working while on edit mode - ios

I'm having the following problem.
I have an app using a UITableView with a custom UITableViewCell. Because of the specs of the app, I need it to be in edit mode always, so on the viewDidLoad I wrote this:
- (void)viewDidLoad
{
MainTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"compose_background.png"]];
[MainTableView setAllowsSelectionDuringEditing: TRUE];
[MainTableView setEditing: TRUE];
[super viewDidLoad];
}
Also, I've implemented the following methods:
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
And several more, but the problem persists and when I swipe a cell the delete button doesn't shows up. Any pointers would be highly appretiated.

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath must return UITableViewCellEditingStyleDelete for each row you want to delete. Swipe-to-delete is disabled in favor of this method when in editing mode.

I don't think there is anyway for the standard swipe to delete to work while the table view is in editing mode, you'd have to respond to gestures and add your own delete button.

Related

iOS11 Drag behavior not working in UITableView

I am facing a problem while developing Drag&Drop iOS11 feature to allow send and receive data between apps.
In the tableView of a view controller, with it's dragDelegate and dropDelegate assigned on viewDidLoad to the view controller itself, I implement the
- (NSArray<UIDragItem *> *)tableView:(UITableView *)tableView itemsForBeginningDragSession:(id<UIDragSession>)session atIndexPath:(NSIndexPath *)indexPath method, but it is never being called.
The drop behavior is working correctly and the table view can consume items from other apps such Photos or Notes. But when I tap a table view row for a couple of seconds, nothing happens. The lift animation doesn't occur and the drag delegate isn't fired.
Any thoughts? Am I missing anything required?
On iPhone, besides setting the dragDelegate you must also set dragInteractionEnabled on the UITableView to true. On iPad, this property is set to true by default.
Please try below delegate methods for re-ordering of cell.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
Implement the following UITableView datasource method in your project.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
[dataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
[self.tableView reloadData];
}

UITableViewCell editingAccessory too far right

Today I observed, that my editingAccessory (UITableViewCellAccessoryDetailButton) is too far on the right side, when the my tableView is in editing mode.
When toggling editing on and off I can see the icon move from their regular position to where they are in editing.
In my implementation I'm using
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
EDIT
There is no more code. It's just a plain UITableViewController and the edit button runs noting but the default -setEditing:animated: behind the scenes (as far as I can tell).
EDIT II
Find the complete ViewController implementation here

UITableviewcell delete button apprearing when I swipe right to left on a cell

I have UITableview and I dont need to edit or delete the cells. So requirement is just view only. But when I swipe on a cell a red delete button appears. Please help how can I disable it.
You have a few options depending on your needs. If you don't need any cell editing of any kind then simply add this method:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Editing defaults to YES so you need to turn it off.
IF you need some editing but no deletion then implement:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
Also, if you don't need either insert or delete, remove the tableView:commitEditingStyle:forRowAtIndexPath: method that may have been added automatically.
Add the following method to your UITableViewDataSource implementation:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}

swipe to delete in tableview not triggering

I have these 3 delegate methods implemented for my swipe to delete handling, but nothing is happening and none of these methods get called.
//returns UITableViewCellEditingStyleDelete
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
//removes deleted object from my tabledata array
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
//checks if data actually can be deleted (all set to yes currently)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
what exactly am i missing? im swiping all day long on my table cells but nothing happens.
Make sure you have the DataSource & Delegate connected up to your view controller
and also make sure you refresh the table when done using [self.tableView reloadData];

how do i create the small round delete buttons in interface builder?

These ones. As seen in the Alarm app when you Edit and Delete an alarm.
Those are not actually custom buttons. They are a property of the delegate method: - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath. as in:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
After that, all you need to do is call [tableview setEditing:YES animated:YES];

Resources