0

我注意到我的 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];
}

我做错什么了吗?我是否错误地设置了我的标签栏?以前有人推过标签栏并且有任何想法我做错了什么可以帮助我吗?任何指导或帮助表示赞赏。提前致谢!

4

0 回答 0