NavigationController推送TabBarViewController

时间:2013-11-14 00:06:24

标签: ios iphone objective-c uitabbarcontroller uitabbar

我注意到我的GoogleMap停止工作,因为它在第一次触摸后变得不活跃。这让我思考,所以我决定使用相同的代码创建一个新项目来检查它是否是代码,并显示它不是我的GoogleMaps代码。我认为这与我如何设置导航栏和标签栏有关。

这就是我所拥有的。我在NavigationController中有一个初始的ViewController。这个视图控制器做了很多事情,其中​​一个是推视控制器。我有一个按钮,将UITabBarController推送到NavigationController堆栈。我在故事板中创建了一个UITabBarController,并为该控制器提供了一个StoryboardID:GRxTabBarViewController。 GRxTabBarViewController有4个视图控制器,PriceViewController,SavingsViewController,InfoViewController和MapsViewController。

然后我创建了这些控制器的头文件和实现文件。这是我在初始视图控制器中推送此标签栏控制器和标签栏时的内容。

-(void)pushTabBar
{
        UIStoryboard *iPhoneStoryBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
        GRxTabBarViewController *tabViewController = (GRxTabBarViewController*) [iPhoneStoryBoard instantiateViewControllerWithIdentifier:@"GRxTabBarViewController"];

        PricesViewController *pricesController = [tabViewController.viewControllers objectAtIndex:0];

        SavingsViewController *savingsController = [tabViewController.viewControllers objectAtIndex:1];

        InfoViewController *infoController = [tabViewController.viewControllers objectAtIndex:2];

        MapsViewController *mapController = [tabViewController.viewControllers objectAtIndex:3];

        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:infoController];
        UINavigationController *savingsNav  = [[UINavigationController alloc] initWithRootViewController:savingsController];

        UITabBarItem *tabBarItem1 = [[tabViewController.tabBar items] objectAtIndex:0];
        [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-prices-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-prices-normal"]];
        UITabBarItem *tabBarItem2 = [[tabViewController.tabBar items] objectAtIndex:1];
        [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-savings-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-savings-normal"]];
        UITabBarItem *tabBarItem3 = [[tabViewController.tabBar items] objectAtIndex:2];
        [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-info-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-info-normal"]];
        UITabBarItem *tabBarItem4 = [[tabViewController.tabBar items] objectAtIndex:3];
        [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"tabbar-map-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabbar-map-normal"]];

        [tabViewController setViewControllers:[NSArray arrayWithObjects:pricesController, savingsNav, navController, mapController, nil]];
        [self.navigationController pushViewController:tabViewController animated:YES];
}

GRxTabBarViewController是一个UITabBarController,在实现文件中有这个。

GRxTabBarViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];


    UIButton *backButton = [[UIButton alloc] init];
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(dismissTab) forControlEvents:UIControlEventTouchUpInside];
    backButton.frame = CGRectMake(0, 0, 20.0f, 44.0f);
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = backBarButtonItem;
    self.navigationItem.hidesBackButton = YES;
}

-(void)dismissTab
{
    [self.navigationController popViewControllerAnimated:YES];
}

我做错了吗?我是否错误地设置了标签栏?有人之前推了一个标签栏,有任何想法,我做错了可以帮助我吗?任何指导或帮助表示赞赏。提前谢谢!

0 个答案:

没有答案