我正在尝试将数据加载到应用程序中,因为细胞进入视图,以便按下单元格的附件按钮,它将具有加载的数据。

我的问题是我正在使用afnetworking,我正在使用这个块代码:

[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]];
. 如此基本上,一旦数据加载,我尝试将附件类型从指示器更改为公开按钮,然后我可以将SEGUE执行到另一个视图,其中将显示我加载的数据。

我的问题是它在完成加载之前将cell.accessorytype更改为按钮。Debug NSLog实际上在其实际完成加载时输出。

在完成时只能启用按钮的最佳方法是什么?我猜这个请求没有由主线程处理。我如何通知该请求已完成处理,因此我可以切换accessorytypes?

谢谢!

有帮助吗?

解决方案

除非您不回收单元格,否则您不应将单元格作为数据所示,因为它表示的数据将随用户滚动而变化。正确的方法是在主队列上分派一个块,该队列更新部分/行坐标中的表条目。然后,您的代码检查该单元格是否可见,然后更新它。它还将以其他方式记录状态,以便当表滚动时,应用正确的状态。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top