gpt4 book ai didi

iphone - 使用等待对话框导航到另一个 ViewController

转载 作者:行者123 更新时间:2023-11-29 13:26:20 26 4
gpt4 key购买 nike

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

否则,您需要在ViewController2viewWillAppear 方法中添加showHUDAddedTo 方法。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com