我用nsarray來存儲所有tableview單元格,我更新單元格後,我調用[tableView reloadData];然後,應用程序將被凍結。我怎樣才能防止呢?iOS的uitableview凍結時,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類有一個reuseIdentifier嗎?隨着你的代碼不能工作,因爲你不想重複使用。 (出於某種原因;)) –