iPhone 开发,如何以编程方式从另一个选项卡调用 NavigationController 后退按钮?
设置如下:
我有一个带有两个选项卡的选项卡栏控制器。第二个选项卡顶部有一个导航控制器,以便我可以查看表格中的详细信息。
在选项卡 #1 上,我有一个按钮。按下此按钮时,会将所选选项卡切换到选项卡 #2。
我的问题是这样的:假设我转到选项卡 #2,然后从表格中选择一行来查看详细信息。然后,我没有点击“后退”按钮返回基本视图,而是选择 tab#1。然后我按下按钮。 Tab#2 加载,但它仍然显示详细视图,而不是我想要的表格视图。
我知道如何以编程方式按下按钮。
[self.navigationController popViewControllerAnimated:YES];
但是,当按钮按下的方法位于 tab#1 的类内部(它对 tab#2 的导航控制器一无所知)时,我该怎么做呢?
希望这是有道理的。预先感谢您的任何帮助!
好吧,我终于开始工作了。建议的解决方案给了我一个很好的起点。这是最终对我有用的代码:
ARFinderAppDelegate appDelegate = (ARFinderAppDelegate)[[UIApplication sharedApplication] delegate];
[appDelegate.booksNavigationController popViewControllerAnimated:YES]; self.tabBarController.selectedIndex = 1;
我必须通过应用程序委托的实例访问包含 NavigationController 的类。我还必须删除“objectAtIndex:1”,因为我的应用程序会崩溃。
感谢大家的帮助,这对于这个 iPhone 开发新手来说是一次很棒的学习经历!
Here's the setup:
I have a tab bar controller with two tabs. There is a navigation controller on top the second tab, so that I can view details from a table.
On tab #1, I have a button. When this button is pressed, it switches the selected tab over to tab #2.
My problem is this: Let's say I go to tab #2, then I select a line from my table to view the detailed information. Then, instead of hitting the "back" button to return to the base view, I select tab#1. Then I press my button. Tab#2 loads, but it is still showing the detailed view, instead of the table view that I want.
I know how to programmatically press the button.
[self.navigationController popViewControllerAnimated:YES];
But how would I do that when the button pressed method is inside the class for tab#1, which knows nothing of tab#2's navigation controller?
Hope that makes sense. Thanks in advance for any help!
Okay, I finally got it to work. The solution that was suggested gave me a good jumping off point. Here is the code that finally worked for me:
ARFinderAppDelegate appDelegate = (ARFinderAppDelegate)[[UIApplication sharedApplication] delegate];
[appDelegate.booksNavigationController popViewControllerAnimated:YES];
self.tabBarController.selectedIndex = 1;
I had to access the class that contained the NavigationController through an instance of my application delegate. I also had to remove the "objectAtIndex:1" because my application would crash.
Thanks for all the help, this has been a great learning experience for this iPhone development newbie!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用你的委托单例。
use your delegate singleton.