executeSelector: withObject: afterDelay не выполняется для MBProgressHUD
У меня есть следующий метод для MBProgressHUD:
[progressHUD performSelector:@selector(hide:)
withObject:[NSNumber numberWithBool:YES]
afterDelay:kMessageHidingDelay];
здесь задержка равна 2,0, однако через 2,0 секунды она не вызывает Hide. Я попытался установить точку останова в функции скрытия, но она не дошла. Любая идея? Вот полный код:
progressHUD = [[MBProgressHUD alloc] initWithView:viewToAttach];
// Add HUD to screen
[viewToAttach addSubview:progressHUD];
progressHUD.labelText = @"Logging In";
progressHUD.removeFromSuperViewOnHide = YES;
// Show the HUD while the provided method executes in a new thread
[progressHUD show:YES];
3 ответа
Решение
Может быть, попытаться выполнить селектор в основном потоке (все изменения пользовательского интерфейса должны быть сделаны в основном потоке)? performSelectorOnMainThread:
Чтобы показать MBProgressHUD Используйте этот код:-
HUD = [[MBProgressHUD alloc] init];
[self.view addSubview:HUD];
HUD.delegate = self;
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
where myTask is
- (void)myTask
{
"Your Code"
}
И тоже Скрыть MBProgressHud
- (void)hudWasHidden:(MBProgressHUD *)hud
{
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}
И если вы хотите показать Hud с вашим CostomView, то используйте этот код
HUD = [[MBProgressHUD alloc] init];
[self.view addSubview:HUD];
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Your Image Name.png"]] autorelease];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = @"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}