与performSegueWithIdentifier一起使用时,MBProgressHUD不会显示

时间:2014-03-31 14:21:29

标签: objective-c mbprogresshud

我的视图控制器上有一个提交按钮,我想...

  • 显示MBProgressHUD 3秒
  • 完成后,转到下一个屏幕。

到目前为止我的代码..

- (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];
}

有了这个,我根本看不到MBProgressHUD。如果我注释掉performSegueWithIdentifier,我会这样做。请帮忙。

1 个答案:

答案 0 :(得分:2)

您可以使用 NSTimer

执行此操作

试试这段代码

-(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];
}

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];
});