0
我正在使用popToViewController方法彈出視圖控制器。我試圖實現的是彈出到UITabBarController的特定索引。popToViewController與特定的UITabBarController選項卡/視圖
NSArray *viewArrays = [self.navigationController viewControllers];
所以我的視圖層次結構是;
<LoginViewController: 0x6b75850>,
<UITabBarController: 0x6ba0b50>,
<RequestViewController: 0x684fe90>,
<ApplyViewController: 0x6845790>
下面的代碼則會彈出我的UITabBarController,但因爲我是在我的UITabBarController的第三種觀點,它會彈出回第三種觀點
[[self navigationController] popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
我想要的是流行到第二我的UITabBarController的視圖。
編輯(答案)
如前所述,我們不推或流行。所以爲了收集你使用的tabBarController;
UITabBarController *myTabController = [self.navigationController.viewControllers objectAtIndex:indexOfYourTabBarControllerInYourNavigationController];
myTabController.selectedIndex = indexToGo;
或者如果您在其中一個tabBarController視圖中;
self.tabBarController.selectedIndex = indexToGo;
第二個示例無法工作 - selectedIndex是一個'NSUInteger' pro perty(因此它不能用作tabBarController)。即使你使用屬性'selectedViewController',你應該將它轉換爲'TabBarController *' - 這樣做,你必須確定它確實是一個'TabBarController' ... –
哦,是的,這是一個錯字:S –
以及如何將我的tabBarController添加到我當前的ViewController中?使用myTabcontroller.selectedIndex?第二個不工作如所述... – Bartu