Download 在UITableview中使用NSURLSession和progressbar动画进行多次下载
我必须在tableview中显示文件列表。每行包含下载按钮。 当我点击下载按钮时,它会显示圆形进度条,用于下载,就像appstore iphone中的一样。下载完成后,我必须在下载按钮上显示勾号图标。对于下载,我使用NSURLSession和downloadtaskwithurl。它还可以同时下载多个文件 这里我使用带有UIcontrol的圆形进度条。 为uitableview创建了customcell,并在tableview中添加了progressbar 但这条路行不通。也不能在UITableview中显示多次下载。它仅在选定单元格中显示进度栏而不显示进度。如果我选择多次下载,tableview将在上次单击的单元格中显示progressbar。有什么帮助吗 这是我使用的代码Download 在UITableview中使用NSURLSession和progressbar动画进行多次下载,download,Download,我必须在tableview中显示文件列表。每行包含下载按钮。 当我点击下载按钮时,它会显示圆形进度条,用于下载,就像appstore iphone中的一样。下载完成后,我必须在下载按钮上显示勾号图标。对于下载,我使用NSURLSession和downloadtaskwithurl。它还可以同时下载多个文件 这里我使用带有UIcontrol的圆形进度条。 为uitableview创建了customcell,并在tableview中添加了progressbar 但这条路行不通。也不能在UITable
-(void)didload{NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"identifier"];
defaultConfigObject.timeoutIntervalForRequest=10.0;
defaultConfigObject.HTTPMaximumConnectionsPerHost = 4;
NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
[myQueue setMaxConcurrentOperationCount:4];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: nil];
NSURL *url = [NSURL URLWithString:signedUrlStr];
NSURLSessionDownloadTask *downloadTask=[defaultSession downloadTaskWithURL:url];
[downloadTask resume];}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
didWriteData:(int64_t)bytesWritten
totalBytesWritten:(int64_t)totalBytesWritten
totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
CGFloat progMax = (float)totalBytesExpectedToWrite;
CGFloat prog = (float)totalBytesWritten;
NSLog(@"data length %lu",(unsigned long)totalBytesWritten);
NSLog(@"Siva %lu",(unsigned long)totalBytesExpectedToWrite);
cell.progressbar.value=0;
cell.progressbar.maxValue=progMax;
cell.progressbar.value=prog;
dispatch_async(dispatch_get_main_queue(), ^(void){
[_tableMonth reloadData];
});
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error {
if (error) {
// Handle error
NSDictionary *userInfo = [error userInfo];
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];
NSString *underlyingErrorDescription = [underlyingError localizedDescription];
NSInteger underlyingErrorCode = [underlyingError code];
NSLog(@"Error desc %@",underlyingErrorDescription);
NSLog(@"Error code %li",(long)underlyingErrorCode);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:[Language get:@"retrykey" alter:@"title not found"]
delegate:self
cancelButtonTitle:[Language get:@"okaykey" alter:@"title not found"]
otherButtonTitles: nil];
[alert show];
}
else {
NSLog(@"File download completed");
}
}
Try this code to update progress bar:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];