0

私はMBProgressHUDで遊んでいます。ビューコントローラ(テーブルビュー)のワーフローは次のようになります。

1)2つの異なるテーブルを切り替えるためにIBActionが呼び出されます2.1)関数reloadAllMonthが呼び出されます(新しいテーブルのデータで配列を初期化します)2.2)MBProgressHUD * HUDが表示されます3)reloadAllMonthが終了します4)HUDが消えます

私の現在のコード:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

        //sparing you the code that determins where the tap occured

        HUD = [[MBProgressHUD alloc]initWithFrame:self.view.frame];
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [self reloadAllMonth];
        allMonthIsActive = YES;
        [MBProgressHUD hideHUDForView:self.view animated:YES];

// some other code table reload etc.
}

何が起こるのですか:

->関数touchesbeganが呼び出されます->3〜4秒間何も起こりません(読み込み時間)->新しいテーブルがポップアップします

質問: HUDが表示されないのはなぜですか?どこで私は間違えましたか ?

4

2 に答える 2

2

同じスレッドで表示と非表示の両方を行うことはできません。これが私が行うことです。

-(void)reloadStuff
{
    [self reloadAllMonth];
    allMonthIsActive = YES;
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    isLoading = NO;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //sparing you the code that determins where the tap occured

    if (isLoading)
        return;
    isLoading = YES;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self performSelectorInBackground:@selector(doStuff) withObject:nil];
}

また、ivar HUDを削除することもできますが、使用していません。

また、viewDidLoadのisLoadingをNOに初期化することを忘れないでください。

isLoading = NO;

幸運を!

于 2012-03-24T14:34:13.297 に答える
0

サーバーから何かをフェッチしていますか?その場合は、uが同期要求または非同期を渡しているかどうかを確認してください。非同期リクエストは、フォローするのに最適です。この方法でMBProgressBarを処理します。

  [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        dispatch_async(dispatch_get_main_queue(), ^{
           //Any UI updates should be made here .
                [MBProgressHUD hideHUDForView:self.view animated:YES];
        });
于 2015-05-20T14:27:23.963 に答える