2012-03-12 14 views
0

この長い質問に対して私は最初から謝罪します。奇妙なクラッシュで終了するMBProgressHUDにデータを渡しています

私のアプリでは、大きなビデオファイル(30-60Mb)をダウンロードします。私は明らかに進歩についてユーザーに伝えたいと思う。ダウンロードはUrban Airshipからのもので、その方法の1つを使用して進捗状況を取得します。しかし、これはTableViewControllerで発生しますが、ダウンロードインジケータ(MBProgressHUD)は別のビューから開始され、UADetailと呼ばれます。

進行状況をあるビューから別のビューに渡すには、シングルトンを使用します。無作為に、それは早く、遅く、まったく起こらないかもしれません、アプリケーションはログでこれでクラッシュします。

2012-03-12 15:13:30.528 isengua-EN [3478:681f] HUD lessonDownloadProgress:0.053478 2012-03-12 15:13:30.553 isengua-EN [3478:707] Lessonlist進歩: 0.055272 2012-03-12 15:13:30.562 isengua-en [3478:707] LLVC downHUDの進捗状況:0.055272 2012-03-12 15:13:30.565 isengua-en [3478:707] - [LessonListViewController> productsDownloadProgress: [CFNumber _getValue:forType:]:メッセージが送信された回数:[Line 57] [StoreFrontDelegate] productsDownloadProgress:0.055272 count:1 2012-03-12 15:13:30.569 isengua-en [3478:6307] * - 割り当て解除されたインスタンス0x83c6e80

まずはLessonListViewControllerです。

- (void)productsDownloadProgress:(float)progress count:(int)count 
{ 
    DataManager *sharedManager = [DataManager sharedManager]; 
    sharedManager.downHUD = [NSNumber numberWithFloat:progress]; 
    NSLog(@"Lessonlist progress: %f", progress); 
    NSLog(@"LLVC downHUD progress: %f", [sharedManager.downHUD floatValue]); 
    UALOG(@"[StoreFrontDelegate] productsDownloadProgress: %f count: %d", progress, count); 
    if (count == 0) { 
     NSLog(@"Downloads complete in LessonListView!"); 
    } 

}

シングルトンは、このようになります。

@implementation DataManager 

@synthesize downHUD; 




+ (DataManager *)sharedManager 
{ 
    static DataManager *sharedManager = nil; 
    static dispatch_once_t predicate; 
    dispatch_once(&predicate, ^{ 
     sharedManager = [[self alloc] init]; 
    }); 
    return sharedManager; 

} 

- (id)init { 
    if (self = [super init]) { 
     downHUD = [NSNumber numberWithFloat:(float)0]; 
    } 
    return self; 
} 


- (void)dealloc { 
// Should never be called, but just here for clarity really. 
    NSLog(@"dealloc called in DataManager"); 
} 



@end 

そして、それは、その後UADetailに読みます。

- (void)showWithLabelDeterminate { 

    HUD = [[MBProgressHUD alloc] initWithView:self.view]; 
    [self.view addSubview:HUD]; 


    // Set determinate mode 
    HUD.mode = MBProgressHUDModeIndeterminate; 
    HUD.delegate = self; 
    HUD.labelText = NSLocalizedString(@"Waiting",""); 

    // myProgressTask uses the HUD instance to update progress 
    [HUD showWhileExecuting:@selector(lessonDownloadProgress) onTarget:self withObject:nil animated:YES]; 
} 


-(void)lessonDownloadProgress 
{ 
    DataManager *sharedManager = [DataManager sharedManager]; 
    HUD.mode = MBProgressHUDModeDeterminate; 
    HUD.progress = [sharedManager.downHUD floatValue]; 
    HUD.labelText = NSLocalizedString(@"DownLoading",""); 

    while (HUD.progress < 1) 
    { 
     [self parentViewController]; 
     NSLog(@"HUD lessonDownloadProgress: %f", HUD.progress); 
     HUD.progress = [sharedManager.downHUD floatValue];      
     NSString *percent = [NSString stringWithFormat:@"%.0f", HUD.progress/1*100]; 
     HUD.detailsLabelText = [percent stringByAppendingString:@"%"]; 
    } 
} 

答えて

0

私はこれに対する解決策を見つけたと思う。 whileループの中にスリープ(50000)を入れた後、停止しました。 ループが速すぎて、sharedManager.downHUDを頻繁にチェックして、他のクラスからの書き込みを妨げている可能性があります。

関連する問題