0

下载按钮放置在 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];}
4

2 回答 2

0

用它来下载一个以上的图像

HCD下载

有关详细信息,请参阅我在从服务器下载图像并保存到数据库中的答案

于 2013-07-01T12:22:51.300 回答
0

我解决了。只需添加到字典:

NSMutableData *myWebData1 = (NSMutableData *)[dict objectForKey:@"myMutData"];

[myWebData1 附加数据:数据];

于 2013-07-02T00:38:03.683 回答