在tabbarController中获取NavigationController的tabbarItem堆栈

时间:2012-11-01 12:39:04

标签: iphone objective-c ios ipad

我想在UIViewControllers中的tabbaritem的特定索引处获取UINavigationController,即UITabBarController堆栈的列表。 请详细说明..! 请大家一起携手

2 个答案:

答案 0 :(得分:1)

如果要在更改选项卡时检查此项,请实施UITabBarControllerDelegate的回调:

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    //if you're using navigationController
    UINavigationController *navC=(UINavigationController *)viewController;
    NSArray *arrayVc=navC.viewControllers;
    NSLog(@"%@",arrayVc);
}

答案 1 :(得分:1)

这样做:

NSArray *arrControllers = self.tabBarController.viewControllers;
for(UIViewController *viewController in arrControllers)
{
   if([viewController isKIndOfClass:[UINavigationController class]])
   {
     //NavigationController
     UINavigationController *navCtrl = (UINavigationController *)viewController;
     NSLog(@"%@",navCtrl.viewControllers);
   }
   else
   {
     // view controller
   }
}