Iphone 如何同时切换选项卡和按下ViewController?
我的应用程序中有两个选项卡,左边的选项卡是一个普通的UIViewController,右边的选项卡是一个导航控制器,里面有一个表视图。我希望允许用户按下左侧选项卡上的按钮并跳转到属于右侧选项卡上表视图中特定行的特定详细视图 在表视图本身中,我没有问题显示特定的详细视图,例如:Iphone 如何同时切换选项卡和按下ViewController?,iphone,objective-c,uitableview,uitabbarcontroller,Iphone,Objective C,Uitableview,Uitabbarcontroller,我的应用程序中有两个选项卡,左边的选项卡是一个普通的UIViewController,右边的选项卡是一个导航控制器,里面有一个表视图。我希望允许用户按下左侧选项卡上的按钮并跳转到属于右侧选项卡上表视图中特定行的特定详细视图 在表视图本身中,我没有问题显示特定的详细视图,例如: [self.navigationController pushViewController:theView animated:YES]; 我还可以使用 self.tabBarController.selectedInde
[self.navigationController pushViewController:theView animated:YES];
我还可以使用
self.tabBarController.selectedIndex = 1; // 1= right tab
但我不知道如何做到这两个。我试过了
self.tabBarController.selectedIndex = 1; // 1= right tab
// alloc and init theView here
[self.navigationController pushViewController:theView animated:YES];
但这不起作用
编辑:
当我尝试上面的代码时,它只是切换选项卡,但不推动视图
我也尝试了criscokid的建议,但什么也没发生
编辑2:
试图解释每个选项卡上的内容:
Root (Tab Bar Controller)
|
--(Left Tab)-- UIViewController (I want to go from here...)
|
--(Right Tab)---UINavigationController
|
---UITableViewController
|
----UIViewController (...to here)
^ specific view with data from specific row
in table view (that is 'theView' from above)
根(选项卡栏控制器)
|
--(左选项卡)--UIViewController(我想从这里开始…)
|
--(右选项卡)--UINavigationController
|
---UITableViewController
|
----UIViewController(…到此处)
^包含来自特定行的数据的特定视图
在表视图中(即上面的“视图”)
如果以相同的方法切换选项卡栏并将ViewController推送到导航控制器堆栈上,则不希望使用self.navigationController。如果我理解正确,您希望将其添加到右侧选项卡上的navigationController。我相信您会希望使用:
[[[[self tabBarController] selectedViewController] navigationController] pushViewController:theView animated:YES];
对我来说,正确的方法是:
UINavigationController * navigationController = (UINavigationController *) [[self tabBarController] selectedViewController];
[navigationController pushViewController:viewController animated:YES];
criscokid的答案有一个多余的调用navigationController
。
这是因为您的
selectedViewController
实际上是一个UINavigationViewController
对我不起作用。如果我正确理解了您的代码,您可以调用导航控制器上的pushview,该导航控制器应该是选项卡栏中当前选定viewcontroller的父级。但是,没有父导航控制器,因为它仅位于右侧选项卡上。您能否尝试再次解释每个选项卡上的内容?我在重复呼叫时犯了相同的错误。这个给我修好了。