UI冻结在self.tableView beginUpdates上

时间:2015-03-24 10:16:44

标签: ios objective-c uitableview

当我想插入新行时,我的UI和UItableview滚动被冻结

在我的桌子里。

程序在前10个结尾处获取新行,如下所示:

dispatch_async(dispatch_get_main_queue(), ^(void)
      {

    [self.tableView beginUpdates];


 NSMutableArray *indexPaths = [NSMutableArray array];
NSInteger currentCount = self.entries.count;
 for (NSUInteger i = 0; i < p.appRecordList.count; i++) {
 [indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+i inSection:0]];
                 }
NSArray *temp_1 =[self.entries arrayByAddingObjectsFromArray:p.appRecordList];
self.entries = temp_1;
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationLeft];
                   [self.tableView endUpdates];

          });
 });

我正在使用我的程序的用户单元格高度,如下所示:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"heightForRowAtIndexPath called");
        return [self heightForBasicCellAtIndexPath:indexPath];
    }
- (CGFloat)heightForBasicCellAtIndexPath:(NSIndexPath *)indexPath {
    static UITableViewCell *sizingCell = nil;
    static dispatch_once_t onceToken;
    static NSString *reuseIdentifier = @"PlaceholderCell2";
    dispatch_once(&onceToken, ^{
        sizingCell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    });

    [self configureCellXXX:sizingCell atIndexPath:indexPath];
    return [self calculateHeightForConfiguredSizingCell:sizingCell];
}

- (CGFloat)calculateHeightForConfiguredSizingCell:(UITableViewCell *)sizingCell {
    [sizingCell setNeedsLayout];
    [sizingCell layoutIfNeeded];

    CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    return size.height + 1.0f; // Add 1.0f for the cell separator height
}

因为我检查了表格冻结是什么时候调用heightForRowAtIndexPath。有没有办法避免这种冻结? 此外,当我滚动越来越长时,冻结时间越长,取决于行数。

0 个答案:

没有答案