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);
}
「floatprogress」をクラスBからクラスAのメソッド「myProgressTask」に渡す必要があります
NSLog:
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
あなたが助けることができることを願っています!前もって感謝します!:)