I used nsarray to store all the tableview cells, after I updated the cells, I called [tableView reloadData]; Then the app will be freeze. How can I prevent that?
=========================================================================
- (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);
}