The editing mode in uitableviewcell only works in ios 5.0 correctly

I created a custom tableviewcell and redefine the method - (void) setEditing:(BOOL)editing animated:(BOOL)animated
to hide UISwitch for edit 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 // ................. } } 

On ios 5.0, this worked. Starting with ios 5.1 and later, it again stopped showing alarmSwitch. Here are some screenshots.

1) EDIT 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 (to redraw the cell), the switch is displayed again. Does anyone know why this could happen? It is strange that in iOS 5.0 it worked like a charm, and now it does not work.

+4
source share
2 answers

The problem is the interaction

 [self.alarmSwitch setEnabled:NO]; 

and setAlpha animations.

The easiest way to solve the problem is to call the setEnabled line inside the animation block before setAlpha as follows:

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

By the way, why do you even set the included NO property? Setting the alpha property to 0 should be sufficient.

+1
source

where do you call the setEditing method of the table view? Just check if it is called when the view is displayed.

0
source

Source: https://habr.com/ru/post/1438157/


All Articles