0

This problem really drives me nuts..been at this for hours now. I have a table view with custom cells. This error occurs mainly when an active cell (cursor in a textfield of this cell) is hidden behind the keyboard or scrolled out of the current visible screen when ENDING the edit mode. However it occurs also at other times, but more rarely. Ok so if I end the edit mode, this one cell doesn't switch back and the delete sign etc. stay still visible. If I scroll away from the active cell and then back so it comes back to view, the cell is displayed correctly. And this problem really only occurs when I change this property UserInteractionEnabled. If I comment it out, the problem is gone. But I need them to be disabled in normal mode, so the whole cell is reactive for selection.

enter image description here

BTW this is anyway a problem, that cells that are outside of the current screen are immediately in non edit mode when switching back, and not transitioning smoothly as they should.

Ok here is my code.

Table view, change edit/non edit:

- (IBAction) editTable:(id)sender
{
    if(self.editing)
    {
        //Change to editing no
        [super setEditing:NO animated:YES];
        [self.tableView setEditing:NO animated:YES];
        //resigns first responder for all textfields
        [self.view endEditing:YES];

        //Remove Done button and exchange it with edit button
        [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit", nil)];
        [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
        self.navigationItem.leftBarButtonItem = nil;
        [self.navigationItem setHidesBackButton:NO animated:YES];
        [((AppDelegate *)[[UIApplication sharedApplication] delegate]) saveContext];
        self.suspendAutomaticTrackingOfChangesInManagedObjectContext = NO;
    } else {
        //Change to editing mode
        [super setEditing:YES animated:YES];
        [self.tableView setEditing:YES animated:YES];

        //Exchange the edit button with done button
        [self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done", nil)];
        [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
        [self.navigationItem setHidesBackButton:YES animated:YES];

        //And insert instead of the back button an add button
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonAction:)];
        [self.navigationItem setLeftBarButtonItem:addButton];

        //[self.tableView layoutIfNeeded];
    }
}

Text field did end editing:

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0];
    MainCategory *mainCategory = [self.fetchedResultsController objectAtIndexPath:indexPath];

    if(textField.text != mainCategory.name){
        mainCategory.name = textField.text;
    }

    self.activeField = nil;
}

And my custom cells behaviour if the edit mode changes:

   - (void) setEditing:(BOOL)editing animated:(BOOL)animated{
        [super setEditing:editing animated:animated];
        if (editing){
            self.iconButton.hidden = NO;
            self.icon.hidden = YES;
            self.costs.hidden = YES;
            self.disclosureIndicator.hidden = YES;
            self.subcategories.hidden = YES;
            self.title.borderStyle = UITextBorderStyleRoundedRect;
            self.title.backgroundColor = [UIColor whiteColor];
            self.title.userInteractionEnabled = YES;
        }  else if (!editing){
            self.iconButton.hidden = YES;
            self.icon.hidden = NO;
            self.subcategories.hidden = NO;
            self.costs.hidden = NO;
            self.disclosureIndicator.hidden = NO;
            self.title.borderStyle = UITextBorderStyleNone;
            self.title.backgroundColor = [UIColor clearColor];
            self.title.userInteractionEnabled = NO;
            [self resignFirstResponder];
        }
    }
MichiZH
  • 5,587
  • 12
  • 41
  • 81

1 Answers1

0

Try in - (IBAction) editTable:(id)sender call [self setEditing:...] instead

    [super setEditing:NO animated:YES];
    [self.tableView setEditing:NO animated:YES];
    //resigns first responder for all textfields
    [self.view endEditing:YES];

and

    //Change to editing mode
    [super setEditing:YES animated:YES];
    [self.tableView setEditing:YES animated:YES];

And if your class is not subclass of UITableViewController, then you need implement:

- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:animated];
}
Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
  • I didn't subclass UITableViewController (but have an embedded table view) so I've lust your last code snippet. But didn't change anything :-( – MichiZH Jan 18 '14 at 07:12