【发布时间】:2015-12-06 09:56:57
【问题描述】:
我使用 nsarray 来存储所有 tableview 单元格,在我更新单元格后,我调用了 [tableView reloadData];然后应用程序将被冻结。我怎样才能防止这种情况发生?
================================================ ============================
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
NSUInteger nodeCount = _newsFeeds.count;
if (cell == nil) {
CustomCell *customCell = [customCells objectAtIndex:indexPath.row - 1];
[customCell setDelegate:self];
[customCell setSelectionStyle:UITableViewCellSelectionStyleNone];
[customCell displayImages];
cell = customCell;
}
return cell;
}
- (void)getData {
[[BackendUtil shareInstance] getData];
}
- (void)updateData:(NSNotification *)notification {
NSDictionary *userInfo = notification.userInfo;
NSMutableArray<Data *> *listOfData = [userInfo objectForKey:@"data"];
_listOfData = listOfData;
[self createCustomCell:listOfData completion:^(NSArray *arr) {
customCells = [arr mutableCopy];
[_tableView reloadData];
}];
}
- (void)createCustomCell:(NSMutableArray<Data *> *)listOfData completion:(void(^)(NSArray *arr))completion {
NSMutableArray *dummyArr = [[NSMutableArray alloc] init];
for (int i = 0 ; i < [data count] ; i++) {
Data *data = [listOfData objectAtIndex:i];
CustomCell *customCell = [[CustomCell alloc] initWithFrame:CGRectMake(posX, posY, width, height) data:data];
[dummyArr addObject:customCell];
}
completion(dummyArr);
}
【问题讨论】:
-
您在
tableview中加载了哪种类型的数据? -
类似于 facebook 的新闻提要,许多文本和一些图像。
-
CustomCell 类是否有重用标识符?由于您不想重用,因此您的代码无法正常工作。 (出于某种原因;))
-
冻结看起来如何...是卡在某个地方还是留下空白视图?
-
卡在某个地方。重新加载表格大约需要 10 秒,我希望用户在重新加载时可以继续滚动表格。
标签: ios iphone uitableview reloaddata