I have a tableView
in which I am enabling swiping the cell to reveal options - in my case, 'share' and 'delete' options by using the following method:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
when a user swipes on a cell to reveal the options and then taps on delete
I put up a UIAlertController
with a confirmation. all is well and good if they say delete as i delete the object in my core data database and my NSFetchedResultController
takes care of updating the tableView
If the user declines to go through with the delete then the cell remains with the slide effect still revealing the options. I'd like it to go away. I know that [tableView reloadData
] or, more efficiently, just reloading the one cell will solve the problem but is there a method call or property on the cell that I've missed that would do the job?
If you end editing on the table view here it will animate the cell back to its normal state.
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
[table setEditing:NO animated:YES];
}
If the table was in an editing state where it shows the delete button next to each cell, this will cause all of those delete buttons to go away, which may not be the behavior you want. In this case, you can immediately set the table view back to editing mode. The animation looks fine:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
[table setEditing:NO animated:YES];
if (yourWasPreviouslyEditingBoolean) {
[table setEditing:YES animated:YES];
}
}
Note that you'll need to track this state yourself. Checking the table view's isEditing value will always return true here.
I haven't been able to find away to tell the cell directly to stop editing.
So, your question is about how to reload one particular cell on a UITableView
? Not hard.
The following code will do the trick:-
NSIndexPath * indexpath = [NSIndexPath indexPathForRow:self.deletedTableRow
inSection: self.deletedTableSection];
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexpath]
withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With