我从照片库导入多张照片,我想用MBProgressHUD
来显示进度。我正在使用QBImagePickerController
导入照片。我的照片已成功导入。但是MBProgressHUD
中的进度条未更新。下面是我的代码MBProgressHUD没有更新进度
-(void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets {
if (imagePickerController.filterType == QBImagePickerControllerFilterTypePhotos) {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];]
// Set the determinate mode to show task progress.
hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
hud.delegate = self;
hud.labelText = NSLocalizedString(@"Importing Photos", nil);
hud.dimBackground = YES;
hud.detailsLabelFont = [UIFont systemFontOfSize:12.0f];
hud.detailsLabelText = NSLocalizedString(@"Please wait...", nil);
hud.progress = 0.0f;
[self importPhotosForArray:assets];
}
[self dismissImagePickerController];
}
- (void) importPhotosForArray:(NSArray *)info {
for (ALAsset *selectedImageAsset in info) {
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary assetForURL:[selectedImageAsset defaultRepresentation].url resultBlock: ^(ALAsset *asset){
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef imageRef = [representation fullResolutionImage];
if (imageRef) {
UIImage *image = [UIImage imageWithCGImage:imageRef];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
// Create a file name for the image
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *imageName = [NSString stringWithFormat:@"photo-%@.png", [dateFormatter stringFromDate:[NSDate date]]];
// Now we get the full path to the file
NSString *fullPathToFile = [self.folder.fullPath stringByAppendingPathComponent:imageName];
// Write out the data.
[imageData writeToFile:fullPathToFile atomically:NO];
sleep(1.0);
progress = ++index/[info count];
[MBProgressHUD HUDForView:self.navigationController.view].progress = progress;
if (progress >= 1.0) {
[[MBProgressHUD HUDForView:self.navigationController.view] hide:YES];
[self reloadData];
}
}
} failureBlock: ^(NSError *error){
// Handle failure.
NSLog(@"Failure");
}];
}
}
是否'MBProgressHUD'成功地隐藏完成后? –
是的,它确实@Mike – kathrineshineshine