使用 MRProgress 更新进度

Update progress with MRProgress

我正在寻求有关尝试使用 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 class 中将 cloudkit 方法从方便 API 转换为 CKOperations。我可以通过日志记录看到进度更新,但我不知道如何将其返回到 viewcontroller。如果我要将它添加到完成处理程序中,那不是只在一切完成后才将它发回吗?这是我更新的代码...

CKManager.h - (void)saveRecord:(NSArray *)records withCompletionHandler:(void (^)(NSArray *records))completionHandler;

CKManager.m - (void)saveRecord:(NSArray *)records 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];

}

如果要显示操作的进度,则必须使用 CKModifyRecordsOperation 并使用 perRecordProgressBlock 方法。