UITableView扩展部分需要花费太多时间

时间:2016-12-28 16:32:56

标签: ios objective-c multithreading uitableview grand-central-dispatch

我有可扩展的UITableView子类。当用户单击标题时,表视图将删除所有行,并仅显示节标题。如果用户再次单击 - 将显示所有行。问题是:当行和部分计数变得太大时 - 表视图冻结并使用户体验崩溃。我试图在不同的帖子中添加每个部分但仍然失败。我用

插入行时出现的下一个代码崩溃了
  

更新后的现有部分中包含的行数(23)必须等于更新前的该部分中包含的行数(0),加上或减去从该部分插入或删除的行数(0已插入,0已删除)并加上或减去移入或移出该部分的行数(0移入,0移出)。

但是我从来没有重新加载我的表视图,也没有改变数据源方法的计数。 扩展代码

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                for (int sec = 0; sec < [self.myCustomTableViewDataSource numberOfSectionsInTableView:self]; sec++) {
//                    NSString *threadNumber = [NSString stringWithFormat:@"inserting_thread_%tu", sec];
//                    dispatch_queue_t customQueue = dispatch_queue_create([threadNumber UTF8String], 0);
//
//                    dispatch_sync(customQueue, ^{
//
//                    });

                    [self.contractedSections removeObject:[NSNumber numberWithInteger:sec]];

                    NSMutableArray *indexPaths = [NSMutableArray new];


                    for (int i = 0; i < [self.myCustomTableViewDataSource resizableTableView:self numberOfRowsInSection:sec]; i++) {
                        [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:sec]];
                    }
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
                    });
                }
            });

0 个答案:

没有答案
相关问题