MBProgress视图和推送视图控制器不显示

时间:2013-08-13 12:05:18

标签: iphone objective-c mbprogresshud

当我尝试将视图控制器推到显示推送VC之前的几秒钟时,MPProgressView不会显示。 viewController应该放在与显示MBProgressView相同的函数中吗?我确保我的MBProgressView在主线程上,我已经在SO上尝试了很多解决方案,并且看不到任何有同样问题的人。我只是试图在viewController加载和推送时显示MBProgressHUD。谢谢!

我正在使用MBProgressView,如下所示:

- (IBAction)pushButton:(id)sender
{

    self.HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.view addSubview:self.HUD];
    self.HUD.labelText = @"Doing stuff...";
    self.HUD.detailsLabelText = @"Just relax";
    self.HUD.delegate=self;

      [self.view addSubview:self.HUD];
   [self.HUD showWhileExecuting:@selector(loadCreate) onTarget:self withObject:nil animated:YES];



}


- (void)loadCreate {

  [self performSelectorOnMainThread:@selector(dataLoadMethodMail) withObject:nil waitUntilDone:YES];
}


-(void)dataLoadMethodMail
{NSLog(@"data load method is displaying");


   SelectViewController *mvc = [[SelectViewController alloc] init];
   [self.navigationController pushViewController:mvc animated:YES];


}

1 个答案:

答案 0 :(得分:2)

你不需要将self.HUD添加到self.view,showHUDAddedTo:为你做。

[self.HUD showWhileExecuting:@selector(loadCreate) onTarget:self withObject:nil animated:YES];

显示hud,直到loadCreate返回。

[self performSelectorOnMainThread:@selector(dataLoadMethodMail) withObject:nil waitUntilDone:YES];

在主线程上调度并返回(在dataLoadMethodMail的实际结束之前)。显示HUD但立即消失。

要解决此问题,请尝试在dataLoadMethodMail完成工作后手动隐藏HUD。

只需替换

 [self.HUD showWhileExecuting:@selector(loadCreate) onTarget:self withObject:nil animated:YES];

[self loadCreate];

并添加

dispatch_async(dispatch_get_main_queue(), ^{
    [self.HUD hide:YES];
});

dataLoadMethodMail

的末尾

PS:不应在主线程上加载数据。