UITableView中的动画影响上一节中的最后一行

时间:2014-04-21 15:34:36

标签: ios objective-c uitableview

我们有一个UITableView,我们对背景和颜色进行了大量定制。我们正在更改节标题的代码以进行展开和折叠。代码与此示例类似:

https://developer.apple.com/library/ios/samplecode/TableViewUpdates/Introduction/Intro.html

当它崩溃时,我们会看到上一部分中的最后一项更改,但随后又恢复到正确的单元格。它看起来像动画到那个单元格,但然后正确地绘制自己。

这是iOS 7问题,我们的一些自定义问题还是其他任何想法?

编辑:我想我解决了这个问题。这是我们更改部分标题被点击时显示的内容的代码。我认为它做两次动画?

- (void)sectionHeaderView:(MenuTableViewHeaderFooterView *)sectionHeaderView sectionOpened:(NSInteger)sectionOpened {

    MenuSectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionOpened];
    sectionInfo.collapsed = NO;

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *collapsedHeaders = [defaults stringArrayForKey:@"menu-collapsed"];
    NSMutableSet *collapsedHeadersSet = [[NSMutableSet alloc] initWithArray:collapsedHeaders];
    [collapsedHeadersSet removeObject:sectionInfo.headerTitle];
    collapsedHeaders = [collapsedHeadersSet allObjects];
    [defaults setObject:collapsedHeaders forKey:@"menu-collapsed"];
    [defaults synchronize];

    NSArray *modules = sectionInfo.modules;

    NSInteger countOfRowsToInsert = [modules count];
    NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
        [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]];
    }

    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationBottom];
    [self.tableView endUpdates];
}

- (void)sectionHeaderView:(MenuTableViewHeaderFooterView *)sectionHeaderView sectionClosed:(NSInteger)sectionClosed {

    MenuSectionInfo *sectionInfo = (self.sectionInfoArray)[sectionClosed];

    sectionInfo.collapsed = YES;

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *collapsedHeaders = [defaults stringArrayForKey:@"menu-collapsed"];
    NSMutableSet *collapsedHeadersSet = [[NSMutableSet alloc] initWithArray:collapsedHeaders];
    [collapsedHeadersSet addObject:sectionInfo.headerTitle];
    collapsedHeaders = [collapsedHeadersSet allObjects];
    [defaults setObject:collapsedHeaders forKey:@"menu-collapsed"];
    [defaults synchronize];
    NSInteger countOfRowsToDelete = [self.tableView numberOfRowsInSection:sectionClosed];

    if (countOfRowsToDelete > 0) {
        NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
        for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
            [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:sectionClosed]];
        }
        [self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
    }
}

如果我更改(插入/删除)RowsAtIndexPaths:withRowAnimation:使用动画UITableViewRowAnimationNone,它看起来没有此问题的动画。

0 个答案:

没有答案