如何在不离开当前视图的情况下关闭 modalViewController?

发布于 2024-12-10 15:53:51 字数 747 浏览 0 评论 0原文

我的应用程序是基于视图的应用程序。第一个视图是登录视图。登录视图后,我有 MainMenuCcontroller,其中有一个 tabBarController:

 @interface RunnoMainMenuController : UIViewController {
IBOutlet UITabBarController *tabBarController;
 }

从登录视图控制器,我将使用这行代码进入 MainMenuController:

 [self presentModalViewController:mainMenu animated:YES];

该控制器有 4 个选项卡。现在我需要在 tabBarItem 的 viewWillAppear 中做一些事情。当我点击 tabBarItem 时,不会调用 viewWillAppear。我在这些 tabBarItem 的视图之一中有一个按钮,它使用presentModalViewController 弹出一个表视图控制器。这个tableView使用dismissModalViewControllerAnimated:YES来消失它。当我弹出这个表格视图并关闭它时,每个 tabBarItem 的 viewWillAppear 都可以正常工作。如果我在 MainMenuController 中关闭 modalViewController 那么它将再次返回到登录视图。如何在不离开当前视图或任何其他解决方案的情况下关闭 modalViewController?提前致谢。

My application is view based app. First view is login view. After login view i have MainMenuCcontroller which has a tabBarController:

 @interface RunnoMainMenuController : UIViewController {
IBOutlet UITabBarController *tabBarController;
 }

From login view controller, i am going to MainMenuController using this line of code:

 [self presentModalViewController:mainMenu animated:YES];

this controller has 4 tabs. Now i need to do some stuff in viewWillAppear of a tabBarItem. viewWillAppear is not called when i tap a tabBarItem. I have a button in one of those tabBarItem's view which pops up a table view controller using presentModalViewController. This tableView uses dismissModalViewControllerAnimated:YES to disappear it. When i pop up this tableview and dismiss it then viewWillAppear of every tabBarItem works fine. If i will dismiss modalViewController in MainMenuController then it will again go back to login view. How can i dismiss modalViewController without leaving current view or any other solution? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿嘿嘿 2024-12-17 15:53:51

您可能需要考虑如何表达您的观点。选项卡栏控制器应始终是窗口的根视图控制器。来自 Apple 文档

部署标签栏界面时,必须将此视图安装为
你的窗口的根目录。与其他视图控制器不同,标签栏
界面永远不应该安装为另一个视图的子视图
控制器。

不要将登录视图显示为根视图,将选项卡栏显示为模态视图控制器,而是尝试相反的方式。选项卡栏控制器作为根,登录视图从最初显示的选项卡的视图控制器中呈现为模态视图控制器。关闭此选项将显示选项卡栏控制器。

You may need to consider how your views are presented. The tab bar controller should always be the window's root view controller. From the Apple docs:

When deploying a tab bar interface, you must install this view as the
root of your window. Unlike other view controllers, a tab bar
interface should never be installed as a child of another view
controller.

Rather than present your login view as the root view and the tab bar as a modal view controller, try it the other way round. The tab bar controller as root, with the login view as presented as a modal view controller from the view controller of whichever tab is shown initially. Dismissing this will then reveal the tab bar controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文