【发布时间】:2017-09-15 06:18:41
【问题描述】:
我正在使用块来下载文件。我需要在块完成后获取对象的值,它应该与块的开始相同。
请检查代码:
-(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]) 块完成,我需要获取第二个单元格。 如果第一次调用 (arr[0]) 块完成,我需要先获取单元格。
希望你能解决我的问题。
【问题讨论】:
-
尝试用__block定义一个变量,
-
__block AttchmentCell *cell = [tableView cellForRowAtIndexPath:indexPath];
-
@AshokPolu 不工作
-
将前两行保留在您的“startDownload”方法中,因为您在开始下载之前没有执行任何操作,请立即尝试
标签: ios objective-c block