0

初めまして、長々とした質問で申し訳ありません。

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

あるビューから別のビューに進行状況を渡すには、Singleton を使用します。ランダムに、早期に発生することも、遅く発生することも、まったく発生しないこともあり、アプリはログにこれを記録してクラッシュします。

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 progress: 0.055272 2012-03-12 15 :13:30.562 isengua-en[3478:707] LLVC downHUD progress: 0.055272 2012-03-12 15:13:30.565 isengua-en[3478:707] -[LessonListViewController >productsDownloadProgress:count:] [57 行目] [StoreFrontDelegate ] productsDownloadProgress: 0.055272 count: 1 2012-03-12 15:13:30.569 isengua-en[3478:6307] * -[CFNumber _getValue:forType:]: 割り当て解除されたインスタンス 0x83c6e80 にメッセージが送信されました

1 つ目は、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:@"%"];
    }
}
4

1 に答える 1

0

私はこれに対する解決策を自分で見つけたと思います。while ループ内に usleep(50000) を入れた後、停止しました。おそらく、ループの実行速度が速すぎて、sharedManager.downHUD をチェックする頻度が高すぎて、他のクラスからの書き込みに干渉していたのでしょう。

于 2012-03-14T10:20:33.023 に答える