我想用NSURLConnection使用MBProgressHUD,但我不知道如何使动画旋转MBProgressHUDModeDeterminate
。如何在使用NSURLConnection时计算MBProgressHUD模式的进度?
基本上我有这样的代码在viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
[self fetchFromServer];
self.HUD = [ [MBProgressHUD alloc] initWithView:self.view];
self.HUD.labelText = @"Loading Schedule...";
[self.view addSubview:self.HUD];
self.HUD.dimBackground = YES;
[self.HUD show:YES];
}
当该视图被加载时,我调用一个方法从数据库中获取。我想要加载MBProgressHUD。然后我希望它在数据被提取后结束。
- (void)fetchFromServer
{
NSURL *url = [[NSURL alloc] initWithString:@"url.com"];
[NSURLConnection sendAsynchronousRequest:[ [NSURLRequest alloc] initWithURL:url] queue:[ [NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
NSString* str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSArray *jsonObj = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&error];
scheduleJSONArray = jsonObj;
// Progress in HUD should end here after scheduleJSONArray is set
[self.HUD hide:YES];
} ];
}
我不知道用什么来更新HUD的进度。任何人都可以协助
感谢
是的。你必须自己添加进度。这不是自主的 – soulshined 2015-02-12 03:17:55