我正在使用來自GitHub的MBProgressHUD並想將正在運行的進程float傳遞給另一個類。將正在運行的float傳遞給另一個類
在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」
的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
希望你能幫助!提前致謝! :)
投票關閉,有輕微變化類似的問題已經存在http://stackoverflow.com/questions/15063078/how-to-access-一個屬性的視圖控制器從另一個iphone/15063118#15063118 – 2013-02-27 13:31:28
該問題是沒有類似於我的... – emotality 2013-02-27 13:41:04
相似性正在傳遞價值從一個類到其他。不是嗎? – 2013-02-27 13:41:55