Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - UITableView - cancel delete row - button animation works only accessory view is present

Overview (Edited)

I have UITableView, when I swipe, the delete button appears, when I touch else where, the delete button just disappears without any animation.

With Accessory

  • If I add an accessory (Disclosure Indicator), when the delete is cancelled, the delete button vanishes with animation.

Without Accessory

  • If I remove the accessory from the table view cell, then delete cancellation doesn't show any animation.

Question

  • I don't want the accessory but i want the delete cancellation animation, is there a way to achieve this ?
like image 762
user1046037 Avatar asked May 26 '12 06:05

user1046037


2 Answers

On iOS 6 this "bug" still exists. There are 2 ways to workaround this problem:

Solution 1:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //[...]
    cell.accessoryView = [UIView new];
    //[...]
}

Solution 2

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.accessoryView = [UIView new];
}

This way when "remove row" is canceled, the button disappears with animation.

like image 190
J. Costa Avatar answered Nov 20 '22 00:11

J. Costa


If you are not using the cell.textlabel property, try to set it to something and then hide it.

cell.textlabel.text = @"something";
Cell.textlabel.hidden = YES;

It should work

like image 20
LombaX Avatar answered Nov 20 '22 00:11

LombaX