gpt4 book ai didi

objective-c - Objective-C - block 代码不按顺序执行?

转载 作者:行者123 更新时间:2023-11-28 19:15:07 27 4
gpt4 key购买 nike

我正在尝试在单元格进入 View 时将数据加载到应用程序中,这样一旦他们按下单元格的辅助按钮,它就会加载数据。

我的问题是我正在使用 AFNetworking 并且我正在使用此 block 代码:

[Request fullRequestWithBlock:^(NSArray *detailedReqFromWeb, NSError *error) {
if (error) {

[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", nil), nil] show];
} else {

NSArray *objs = [NSArray arrayWithObjects: [detailedReqFromWeb objectAtIndex: 0], [detailedReqFromWeb objectAtIndex: 1], [detailedReqFromWeb objectAtIndex: 2], [detailedReqFromWeb objectAtIndex: 3], [detailedReqFromWeb objectAtIndex: 4], [detailedReqFromWeb objectAtIndex: 5], nil];
NSArray *keys = [NSArray arrayWithObjects:@"Risk", @"Destination", @"Source", @"Customer", @"Subcategory", @"Deployment", nil];

NSMutableDictionary *detailsforRequestDictionary = [[NSMutableDictionary alloc] initWithObjects:objs forKeys:keys];

[request addEntriesFromDictionary: detailsforRequestDictionary];

NSLog(@"%@ Finished Loading", [idNumbers objectAtIndex:row]);
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

}

} forID: [[idNumbers objectAtIndex:row] substringFromIndex:1]];

所以基本上,我试图在加载数据后将附件类型从指示器更改为披露按钮,这样我就可以执行转场到另一个 View ,在该 View 中将显示我加载的数据。

我的问题是它在完成加载之前将 cell.accessoryType 更改为按钮。 debug NSLog 在真正完成加载时实际输出。

只有在加载完成后才启用按钮的最佳方法是什么?我猜请求没有被主线程处理。为什么我会收到请求已完成处理的通知,以便我可以切换 accessoryTypes?

谢谢!

最佳答案

除非您不回收单元格,否则您永远不应该保留单元格引用,因为它代表的数据会随着用户滚动而改变。正确的方法是在主队列上分派(dispatch)一个 block 来更新部分/行坐标中的表条目。然后您的代码检查该单元格是否可见,然后更新它。它还会以其他方式记录状态,以便在表格滚动时应用正确的状态。

关于objective-c - Objective-C - block 代码不按顺序执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677912/

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