UITableView动画故障



当我用动画重新加载几个单元格时,在一些其他非动画单元格之间出现了一个空格。然而,最有趣的是,这种情况有时会发生,有时不会。下面的代码来自tableView委托的didselect函数。

 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];

为什么要写这最后一行?

 [self.tableView reloadData];

尝试删除它-我认为它干扰了动画

最新更新