如何在不离开当前视图的情况下关闭 modalViewController?
我的应用程序是基于视图的应用程序。第一个视图是登录视图。登录视图后,我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要考虑如何表达您的观点。选项卡栏控制器应始终是窗口的根视图控制器。来自 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:
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.