我正在寻求帮助,尝试使用MRProgress框架更新进度指示器。我能够设置进度指示器,但我不知道如何计算和更新其进度。我正在使用CloudKit并尝试在保存CKRecord时显示进度。有人可以给我一些方向吗?提前谢谢!
self.hud = [MRProgressOverlayView showOverlayAddedTo:self.myCollectionView animated:YES];
self.hud.mode = MRProgressOverlayViewModeDeterminateCircular;
self.hud.titleLabelText = @"Uploading...";
// prepare the CKRecord and save it
[self.ckManager saveRecord:[self.ckManager createCKRecordForImage:self.imageDataAddedFromCamera] withCompletionHandler:^(CKRecord *record, NSError *error) {
if (!error && record) {
NSLog(@"INFO: Record saved successfully for recordID: %@", record.recordID.recordName);
// need to get the recordID of the just saved record before adding the CID to the CIDArray
self.imageDataAddedFromCamera.recordID = record.recordID.recordName;
[self.imageLoadManager addCIDForNewUserImage:self.imageDataAddedFromCamera]; // update the model with the new image
// update number of items since array set has increased from new photo taken
self.numberOfItemsInSection = [self.imageLoadManager.imageDataArray count];
//[MRProgressOverlayView dismissAllOverlaysForView:self.view animated:YES];
[self.hud dismiss:YES];
[self.hud removeFromSuperview];
} else {
NSLog(@"ERROR: Error saving record to cloud...%@", error.localizedDescription);
[self alertWithTitle:@"Yikes!" andMessage:@"We encountered an issue trying to upload your photo to the cloud."];
}
}];
更新:在我的CKManager类中将easykit API中的cloudkit方法转换为CKOperations。我可以通过日志记录看到进度更新,但我不知道如何将其恢复到viewcontroller。如果我要将它添加到完成处理程序中,那么只有在一切完成后才将其发回?这是我更新的代码......
CKManager.h - (void)saveRecord:(NSArray *)记录withCompletionHandler:(void(^)(NSArray * records))completionHandler;
CKManager.m - (void)saveRecord:(NSArray *)记录withCompletionHandler:(void(^)(NSArray *))completionHandler {
NSLog(@"INFO: Entered saveRecord...");
CKModifyRecordsOperation *saveOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:records recordIDsToDelete:nil];
saveOperation.perRecordProgressBlock = ^(CKRecord *record, double progress) {
if (progress <= 1) {
NSLog(@"Save progress is: %f", progress);
}
};
saveOperation.completionBlock = ^ {
NSLog(@"Save operation completed!");
completionHandler(records);
};
[self.publicDatabase addOperation:saveOperation];
}