如何在块完成后保持对象的值相同?
问题描述:
我正在使用块下载文件。我需要在块完成后获得对象的值,它应该与块的开始相同。如何在块完成后保持对象的值相同?
请检查代码:
-(void)startDownloadFile:(NSDictionary *)dict withAllFile:(NSMutableArray *)arr withTable:(UITableView *)tableView{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[arr indexOfObject:dict] inSection:0];
AttchmentCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[manager startDownloadCallWithRequestJson:dictDownloadRequest withCompletion:^(NSString *strResponce, NSDictionary *RESPONSE_DATA) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"%@",cell.lblName.text); // cell overites its value of last method
[cell.downloadButton completeProgressing];
}];
}
我打电话此方法:
[self startDownloadFile:arr[0] withAllFile:arr withTable:tableView];
[self startDownloadFile:arr[1] withAllFile:arr withTable:tableView];
问题:
我总是获得第二块ARR的单元格的值[1]。
预期:
如果第二呼叫(ARR [1])块complates我需要小区2。 如果第一呼叫(ARR [0])的块complates我需要首先获得细胞。
希望你会清楚我的问题。
答
这是不正确的异步操作之前得到的索引路径上的细胞,并进行了更改异步操作后的细胞,因为这时该索引路径的小区可以是不同的细胞,你可能因此要改变错误的单元格。
计算基于索引路径上的异步操作后的细胞(即,调度到主队列块内)。
+0
大家好,我的目的是之前和异步块后改变..之前我需要更改单元格显示下载开始,完成后需要显示下载完成 – user3772344
与限定具有__block可变尝试, – AshokPolu
__block AttchmentCell *细胞= [的tableView的cellForRowAtIndexPath:indexPath]; – AshokPolu
@AshokPolu不工作 – user3772344