문제

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.

도움이 되었습니까?

해결책

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];
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top