gpt4 book ai didi

iphone - dispatch_async 进入无限循环

转载 作者:行者123 更新时间:2023-11-28 20:21:19 26 4
gpt4 key购买 nike

我正在开发一个应用程序,我必须在其中从 JSON 获取数据并在 UITableView 中显示。正在后台获取数据。但它似乎进入了无限循环。

任何帮助将不胜感激。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
queue = dispatch_queue_create("com.events.app", NULL);
dispatch_async(queue, ^{
[self load];
//Need to go back to the main thread since this is UI related
dispatch_async(dispatch_get_main_queue(), ^{
// store the downloaded image in your model
Events *evObj = [eventsArray objectAtIndex:[indexPath row]];
NSLog(@"evObj = %@",evObj);
cell.textLabel.text = evObj.eName;
cell.detailTextLabel.text = @"Detailed Text";
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
});
});
// Configure the cell...



return cell;
}

最佳答案

它进入循环,因为发送 -reloadRowsAtIndexPaths:withRowAnimation: 将触发 UITableView 向您的数据源请求另一个单元格 -tableView:cellForRowAtIndexPath:

如果您想异步更新单元格,则必须直接更新一个 UI 元素,但要避免重新加载整个单元格。如果事情没有自动更新,您可以在更新后发送 -setNeedsDisplay-setNeedsLayout

关于iphone - dispatch_async 进入无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15810520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com