下载按钮放置在 UITableView 中的所有单元格上。当我一次单击一次并等待它完成下载时,我收到的文件很好,但是当我在下载按钮上单击 2 个或更多时,我收到的文件都混在一起了。请有人帮助我。
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSMutableDictionary *dict = [self getConnectionInfo:connection];
NSInteger bytes = [data length] + [[dict objectForKey:@"receivedBytes"] intValue];
[dict setObject:[NSNumber numberWithInt:bytes] forKey:@"receivedBytes"];
int row = [[dict objectForKey:@"row"] intValue];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[self.aTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
[myWebData appendData:data];
[dict setObject:myWebData forKey:@"myData"];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//Write file to folder
NSMutableDictionary *dict = [self getConnectionInfo:connection];
[self.activeConnections removeObject:dict];
NSString *fileName = [dict valueForKey:@"fName"];;
DLOAD_PATH = [NSString stringWithFormat:@"%@/%@",DLOAD_PATH0,fileName];
NSData *myData1 = [dict objectForKey:@"myData"];
[myData1 writeToFile:DLOAD_PATH atomically:YES];}