我正在尝试使用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];
}

最佳答案

代替,

- (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方法中添加viewWillAppear方法。

关于iphone - 使用等待对话框导航到另一个ViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13020274/

10-13 04:27