1

我正在尝试使用MBProgressHUD在我的应用程序中使用等待对话框。

我的应用程序中有一个按钮。当用户点击它时,我们导航到另一个 viewController:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewController2 *yourViewController = (ViewController2 *)[storyboard instantiateViewControllerWithIdentifier:@"FavoritePage"];
[self.navigationController pushViewController:yourViewController animated:YES];

如您所知,它也可以从interface builder.

问题是加载下一页需要很短的时间,我想在此期间显示一个等待对话框:

- (IBAction)navigation:(id)sender {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ViewController2 *yourViewController = (ViewController2 *)[storyboard instantiateViewControllerWithIdentifier:@"FavoritePage"];
    [self.navigationController pushViewController:yourViewController animated:YES];
}

但它不起作用。

当我删除与导航相关的代码时,只需使用它:

[MBProgressHUD showHUDAddedTo:self.view animated:YES];

等待对话框出现,但是当我使用导航代码和这条线时,等待对话框不显示并且导航工作。

我怎样才能让它们一起工作?

只是想添加它来隐藏等待对话框,我也有这个:

- (void) viewDidDisappear:(BOOL)animated {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
4

2 回答 2

1

代替,

- (IBAction)navigation:(id)sender {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ViewController2 *yourViewController = (ViewController2 *)[storyboard instantiateViewControllerWithIdentifier:@"FavoritePage"];
    [self.navigationController pushViewController:yourViewController animated:YES];
}

尝试,

- (IBAction)navigation:(id)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ViewController2 *yourViewController = (ViewController2 *)[storyboard instantiateViewControllerWithIdentifier:@"FavoritePage"];
    [self.navigationController pushViewController:yourViewController animated:YES];
    [MBProgressHUD showHUDAddedTo:self.navigationController.view  animated:YES];
}

否则,您需要showHUDAddedToViewController2's方法中添加viewWillAppear方法。

于 2012-10-23T04:28:07.007 回答
0

我认为问题出在你- (IBAction)navigation:(id)sender {} 身上,因为你首先展示了MBProgressHUD然后推送到ViewController2. 因此, MBProgressHUD已经展示了它,但它也推动了新的观点。

如果你想显示等待标志,那么你可以使用MBProgressHUD定时器。将计时器设置为 1.0 或 2.0 秒。在那个调用navigation方法之后。使计时器无效并删除MBProgressHUD.

否则,您可以使用

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethod) name:@"notificationName" object:nil];

在 `- (IBAction)navigation:(id)sender {}。

NSNotification从另一个视图中调用它,例如[[NSNotificationCenter defaultCenter] postNotificationName:@"notificationName" object:nil]; `

于 2012-10-23T04:17:18.960 回答