MBProgressHUD не будет показывать - PullRequest
0 голосов
/ 24 марта 2012

Я играю с MBProgressHUD.рабочий процесс в viewcontroller (tableview) выглядит следующим образом:

1) вызывается 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.
}

что происходит:

-> функция touchSbegan получаетВызванный -> ничего не происходит в течение 3-4 секунд (время загрузки) -> всплывает новая таблица

вопрос: почему не отображается HUD?где я ошибся?

Ответы [ 2 ]

2 голосов
/ 24 марта 2012

Вы не можете одновременно показывать и скрывать в одной теме, вот что я бы сделал:

-(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, вы его не используете.

И не забудьте инициализировать isLoading в viewDidLoad для NO:

isLoading = NO;

Удачи!

0 голосов
/ 20 мая 2015

Ты что-нибудь получаешь с сервера? Если это так, пожалуйста, проверьте, передаете ли вы синхронный запрос или асинхронный. Асинхронные запросы лучше всего следовать. Обрабатывайте 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];
        });
...