Pregunta

I have a submit button on my view controller which I'd like to..

  • Show MBProgressHUD for 3 seconds
  • Once complete, move to the next screen.

The code I have so far..

- (IBAction)submit:(id)sender
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [hud setMinShowTime:3];
    [hud setLabelText:@"Processing"];
    [hud hide:YES];

    [self performSegueWithIdentifier:@"showAuditViewControllerBravo" sender:self];
}

With this I don't see the MBProgressHUD at all. If I comment out the performSegueWithIdentifier I do. Please help.

¿Fue útil?

Solución

you can do this with NSTimer

try this code

-(void)stopAnimationAndMove{

   [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
   [self performSegueWithIdentifier:@"showAuditViewControllerBravo" sender:self];
}

- (void)viewDidLoad
{
   [super viewDidLoad];

   MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
   [hud setMinShowTime:3];
   [hud setLabelText:@"Processing"];

   [NSTimer scheduledTimerWithTimeInterval:3.0
                               target:self
                               selector:@selector(stopAnimationAndMove)
                               userInfo:nil repeats:NO];
}

with dispatch_after

 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 [hud setLabelText:@"Progress"];
 dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 3.0 * NSEC_PER_SEC); // provide value as required. time here is 3 sec
 dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [self performSegueWithIdentifier:@"showAuditViewControllerBravo" sender:self];
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top