私はUITableViewCellでそれぞれのボタンをクリックしてサーバーからファイルをダウンロードする必要があります。ユーザーが1つのセルのダウンロードでダウンロードするボタンを開始します。ダウンロードの完了後、コアデータを保存します。これまですべてがうまくいった。しかし、現在のファイルをダウンロードしている間に、ユーザーがCellの別のファイルをダウンロードするようにタップすると、ダウンロードしてコアデータに保存し、再生できるようにする必要があります。ボタンはそれらをダウンロードし、コアデータに保存する必要があります。ここで私のコード。ここでサーバーからファイルを1つずつダウンロードします
NSString *url=[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"voice"];
NSLog(@"%@",url);
//NSURL *voiceUrl=[NSURL URLWithString:url];
tempDict=[[NSMutableDictionary alloc]init];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"msg_id"] forKey:@"msg_id"];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"to"] forKey:@"to"];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"from"] forKey:@"from"];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"time"] forKey:@"time"];
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:cell.playButton.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"], nil];
animatedImageView.animationDuration = 3.0f;
animatedImageView.animationRepeatCount = 10;
[animatedImageView startAnimating];
[cell1.playButton addSubview: animatedImageView];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/octet-stream",@"video/3gpp",@"audio/mp4",nil];
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error)
{
NSLog(@"Error: %@", error);
} else
{
NSData *data=[[NSData alloc]initWithData:responseObject];
//Here I'm saving file to local storage then updating UI.
[self sentMsgSaveWithData:data orUrl:@"" withBool:YES withMsg_ID:@"" withDict:tempDict];
}
}];
[dataTask resume];
私は、ユーザーが別のセルをタップした場合のみ、私はセル内の複数のボタンのタップで複数のファイルをダウンロードする必要がit.Butをダウンロードしてる時に一つだけのファイルをダウンロードするために管理し、その完了後。 私はこれを実装するために多くの努力を払っています。いくつかの提案をお願いします。
ありがとうございます。
が重複する可能性[ファイルをダウンロードしてAFNetworking 3.0を使用してローカルに保存する方法?](http://stackoverflow.com/questions/35137749/how-to-download-files-and-save-to-local-usin g-afnetworking-3-0) –
あなたはopenurl(NSUrl *)mypicUrl:(Int)cellrowと言う方法でURLを渡します。したがって、どのセルを再ロードする必要があるのかを知ることができます。 – user3344236