我正在使用来自 GitHub 的 MBProgressHUD,并希望将正在运行的进度浮动传递给另一个类。
在 A 类:
-(void)methodName
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.navigationController.view addSubview:HUD];
HUD.mode = MBProgressHUDModeAnnularDeterminate;
HUD.delegate = self;
HUD.dimBackground = YES;
HUD.labelText = @"Loading";
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
}
- (void)myProgressTask
{
HUD.progress = progress;
}
B 类:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
expectedLength = [response expectedContentLength];
currentLength = 0;
HUD.mode = MBProgressHUDModeDeterminate;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
currentLength += [data length];
float progress = currentLength / (float)expectedLength;
NSLog(@"%f", progress);
}
需要将 B 类的“浮动进度”传递给 A 类的方法:“myProgressTask”
NS日志:
2013-02-27 15:23:14.006 [8209:c07] 0.161726
2013-02-27 15:23:14.329 [8209:c07] 0.253171
2013-02-27 15:23:14.718 [8209:c07] 0.436063
2013-02-27 15:23:15.941 [8209:c07] 0.527508
2013-02-27 15:23:16.230 [8209:c07] 0.618954
2013-02-27 15:23:16.238 [8209:c07] 0.710400
2013-02-27 15:23:16.614 [8209:c07] 0.893291
2013-02-27 15:23:16.615 [8209:c07] 0.984736
2013-02-27 15:23:16.618 [8209:c07] 1.000000
希望你能帮忙!提前致谢!:)