使用MRProgress更新进度 [英] Update progress with MRProgress

查看:103
本文介绍了使用MRProgress更新进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求有关尝试使用MRProgress框架更新进度指示器的帮助。我能够设置进度指示器,但是我不知道如何计算和更新其进度。我正在使用CloudKit,并试图在保存CKRecord时显示进度。有人可以给我一些指导吗?

I'm looking for help with trying to update a progress indicator using the MRProgress framework. I was able to set up the progress indicator, but I have no idea how to calculate and update its progress. I'm using CloudKit and trying to show the progress when saving a CKRecord. Could someone provide me some direction? Thanks in advance!

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类中的cloudkit方法从便捷API转换为CKOperations。我可以看到通过日志记录来更新进度,但是看不到如何将其返回给ViewController。如果我要将其添加到完成处理程序中,难道不是只有一切完成后才将其发送回去吗?这是我更新的代码...

Update: Converted cloudkit methods from convenience API to CKOperations in my CKManager class. I can see the progress updating through logging, but I don't see how to get it back to the viewcontroller. If I were to add it to the completion handler, wouldn't that only send it back once everything is completed? Here's my updated code...

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

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

CKManager.m
-(void)saveRecord:(NSArray *)带CompletionHandler的记录:(void(^)(NSArray *)) completeHandler {

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方法。

if you want to show the progress of an operation, then you have to use the CKModifyRecordsOperation and use perRecordProgressBlock method.

这篇关于使用MRProgress更新进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆