As is done in the iPhone Mail app, I would like have the "Delete" button which appears on swiping an editable table cell from right to left to animate when it is dismissed (by way of tapping elsewhere than the Delete button on the UITableViewCell
). Instead, my Delete button immediately disappears when it is dismissed.
To invoke the Delete button on swiping a table cell in the first place, I have added (to the class which is the UITableViewDataSource
and UITableViewDelegate
for the UITableView
in question):
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
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
}
}
Is there something I might add to this which will handle the animation of the Delete button when it is dismissed? Thank you!
I had the same problem, just now found out that there is some problem when we have empty cell.textLabel.text. Try add in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:
{
{...} // omitted code
cell.textLabel.text = @"whatever";
cell.textLabel.hidden = YES;
}
With this swipe button dismiss proper, but WHY? PS: tested with custom cells and built i.n
You should not need to animate the dismissal manually, it works the same way as invoking it so not sure why it is behaving differently in your app.
Are you using custom cells by any chance? As a thought for you to try, change the shouldIndentWhileEditingRowAtIndexPath:
method to return NO and see if it changes anything. The only thing I can think of is that your content indentation is interfering with the delete button area in a way that the animation can't be performed or is not behaving as it should.
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
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