Metin Say
Metin Say

Reputation: 435

UITableView Animation Glitch

When I reload a couple of cells with animation, between some other non-animated cells a space occurs. However, the most interesting is that it sometimes happens and sometimes not. The following code is from the didselect function of the tableView delegate.

 NSArray *taskArray;
    int count ;
    if (array.count >= indexPath.row+1) {
        taskArray = [[dictionary objectForKey:[NSString stringWithFormat:@"Week %i",indexPath.section+1]] objectForKey:[array objectAtIndex:indexPath.row]];
        count = [taskArray count];
    }else{

        count = 0;

    }
    numberOfAddedRows = count;

    selectedRow = -1;
    selectedSection = -1;


    int numberOfRows = [[[dictionary objectForKey:[NSString stringWithFormat:@"Week %i",indexPath.section+1]] allKeys] count];

    [self.tableView beginUpdates];





    /*for (int i = numberOfRows-1+numberOfAddedRows; i > indexPath.row; i--) {
     [array addObject:[NSIndexPath indexPathForRow:i-1 inSection:indexPath.section]];
     }*/

    if (!editMode) {


       [array__ removeAllObjects];
        for (int i =  indexPath.row+numberOfAddedRows; indexPath.row < i; i--) {

            [array__ addObject:[NSIndexPath indexPathForRow:i inSection:indexPath.section]];
        }




        [self.tableView deleteRowsAtIndexPaths:array__ withRowAnimation:UITableViewRowAnimationMiddle];



    }else{

        [array__ removeAllObjects];
        for (int i =  indexPath.row+numberOfAddedRows+1; indexPath.row < i; i--) {
            [array__ addObject:[NSIndexPath indexPathForRow:i inSection:indexPath.section]];
        }


        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

        UITextField *textField = (UITextField*)[cell viewWithTag:2];
        [textField resignFirstResponder];




        [self.tableView deleteRowsAtIndexPaths:array__ withRowAnimation:UITableViewRowAnimationMiddle];



    }





    [self.tableView endUpdates];

     [self.tableView reloadData];

Upvotes: 0

Views: 398

Answers (1)

Ilea Cristian
Ilea Cristian

Reputation: 5851

Why are you having this last line?

 [self.tableView reloadData];

Try to remove it - I think it interferes with the animation.

Upvotes: 1

Related Questions