文件从UITableView Cell下载 - 混合起来

时间:2013-07-01 12:11:00

标签: uitableview nsurlconnection

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

2 个答案:

答案 0 :(得分:0)

使用它下载多个图像

HCDownload

有关详细信息,请参阅Downloading images from server and saving into Database

上的答案

答案 1 :(得分:0)

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

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

[myWebData1 appendData:data];