gpt4 book ai didi

ios - 使用 MRProgress 更新进度

转载 作者:行者123 更新时间:2023-11-29 02:10:08 25 4
gpt4 key购买 nike

我正在寻求有关尝试使用 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."];
}
}];

更新:将 cloudkit 方法从便捷 API 转换为我的 CKManager 类中的 CKOperations。我可以通过日志记录看到进度更新,但我不知道如何将其返回到 View Controller 。如果我将其添加到完成处理程序中,那不是只有在一切完成后才将其发送回来吗?这是我更新的代码...

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

最佳答案

如果你想显示操作的进度,那么你必须使用 CKModifyRecordsOperation并使用 perRecordProgressBlock 方法。

关于ios - 使用 MRProgress 更新进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29376714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com