4

I have made a custom tableviewcell and override the method
-(void) setEditing:(BOOL)editing animated:(BOOL)animated
so as to hide a UISwitch for the editing mode.

This is my code

-(void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];

    if (animated==YES) {
        // With animation
        if (editing == NO) {
            // Editing stopped
            [UIView animateWithDuration:0.3
                             animations:^{
                                  [self.alarmSwitch setAlpha:1.0];
                             }];
            [self.alarmSwitch setEnabled:YES];
        } else {
            // Editing started
             [UIView animateWithDuration:0.3 
                             animations:^{
                                  [self.alarmSwitch setAlpha:0.0];
                             }];
            [self.alarmSwitch setEnabled:NO];
        }
    } else {
        // Without animation
        // .................
    }
}

In ios 5.0 this worked. From ios 5.1 and later it stopped showing again the alarmSwitch. Here are some screenshots.

1) EDITING MODE

enter image description here

2) AFTER EDITING (IOS 5.0)

enter image description here

3) AFTER EDITING (IOS 5.1 and later)

enter image description here

If i scroll up and then scroll down (so as to redraw the cell) the switch is presented again. Does anybody have any idea why this could happen? It is strange that in iOS 5.0 worked like a charm and now it doesn't work.

Tomasz Wojtkowiak
  • 4,910
  • 1
  • 28
  • 35
gsach
  • 5,715
  • 7
  • 27
  • 42

2 Answers2

1

The problem seems to be the interaction of the

[self.alarmSwitch setEnabled:NO];

and the setAlpha animation.

The simplest way to solve the problem is to call the setEnabled line inside the animation block before setAlpha like this:

[UIView animateWithDuration:0.3
                         animations:^{
                             [self.alarmSwitch setEnabled:NO];
                             [self.alarmSwitch setAlpha:0.0];
                         }];

By the way, why are you even setting the enabled property to NO? Setting the alpha property to 0 should be enough.

adamsiton
  • 3,642
  • 32
  • 34
0

where are you calling the setEditing method of the tableView?? Just check if it gets called when the view is displayed.

iSaalis
  • 622
  • 1
  • 8
  • 14
  • In debug mode I can see that the setEditing is called. The problem is it that it does never do the animation. Remember that in ios 5.0 it works fine. – gsach Oct 08 '12 at 09:52