如何用box sdk显示渐进式hud /活动指示器

时间:2014-01-10 12:11:54

标签: ios box-api

  

我已经在我的ios应用程序中成功集成了BOX SDK,但是在将文件上传到框时面临问题,我的问题是我在成功完成上传成功块后无法隐藏进度指示器/ hud。我不太了解块代码。我已使用此代码上传文件

-(void)upload{

     BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
     builder.name = @"Logo_Box_Blue_Whitebg_480x480.jpg";
     builder.parentID = folderID;

     NSString *path = [[NSBundle mainBundle] pathForResource:@"Logo_Box_Blue_Whitebg_480x480.jpg" ofType:nil];
     NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:path];
     NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
     long long contentLength = [[fileAttributes objectForKey:NSFileSize] longLongValue];


     [[BoxSDK sharedSDK].filesManager uploadFileWithInputStream:inputStream contentLength:contentLength MIMEType:nil requestBuilder:builder success:fileBlock failure:failureBlock progress:nil];

}
  

成功上传后,此方法被调用,我想在此块中隐藏我的进度hud,如何执行此操作。

BoxFileBlock fileBlock = ^(BoxFile *file)
{
      // manipulate resulting BoxFile
};

BoxAPIJSONFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response,  NSError *error, NSDictionary *JSONDictionary)
{
      // handle failed upload
};

1 个答案:

答案 0 :(得分:0)

您是否尝试从成功和失败块中隐藏HUD? 他们中的任何一个最终都会被召唤。

在上面的代码中,我看不到任何HUD对象或属性 目前还不清楚upload方法是否属于带有HUD指针的ViewController类。

选项A

假设上传方法属于具有HUD的视图控制器。

MyAwesomeBOXUploadViewController.m中的

类声明(替换为您的视图控制器类名:))

@interface MyAwesomeBOXUploadViewController ()
@property (nonatomic, readwrite, strong) MyHUD *uploadHUD;
@end

成功失败阻止MyAwesomeBOXUploadViewController实现。

// using weak pointer to self to avoid retain loop
__weak MyViewControllerClass *weakSelf = self;
BoxFileBlock fileBlock = ^(BoxFile *file)
{
    [weakSelf.uploadHUD stop];
     // manipulate resulting BoxFile
};

BoxAPIJSONFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response,  NSError *error, NSDictionary *JSONDictionary)
{
     [weakSelf.uploadHUD stop];
     // handle failed upload
};

选项B

如果upload方法不是视图控制器的一部分,并且您没有HUD指针,那么您需要将成功和失败回调传播到视图控制器。为了传播成功/失败,你有很多选择。有人可能会考虑使用块回调或通知。

BTW,Blocks非常有用,Apple提供了有关块编程的精彩文档: https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html