MBProgressHUD无法显示

时间:2014-07-04 08:54:23

标签: ios objective-c mbprogresshud

在我移动到下一个视图控制器之前,我想显示MBProcessHUD 5秒钟。这是当前的实现

-(void)login
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
    [hud setDimBackground:YES];
    [hud setOpacity:0.5f];
    [hud show:YES];
    [hud hide:YES afterDelay:10.0];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:@"accountTableViewController"];
    [self.navigationController pushViewController:obj animated:YES];
}

不幸的是,HUD根本不显示。

1 个答案:

答案 0 :(得分:4)

尝试:

-(void)login
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
    [hud setDimBackground:YES];
    [hud setOpacity:0.5f];
    [hud show:YES];
    [hud hide:YES afterDelay:5.0];

    [self performSelector:@selector(pushView) withObject:nil afterDelay:5.0];
}

- (void) pushView {

   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
   UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:@"accountTableViewController"];
   [self.navigationController pushViewController:obj animated:YES];

}

虽然这应该可行,但我假设您将进行一些处理以尝试登录用户?在这种情况下,您可以使用:

    [hud showAnimated:YES whileExecutingBlock:^{
       //Log the user in:
    } completionBlock:^{
      //Then push the new view here, the hud will automatically dismiss. 
    }];