Programmatically pressing a UITabBar button in Xcode

前端 未结 6 1271
无人及你
无人及你 2020-12-17 17:34

Sorry for the newbie question. I have a UITabBar in my main window view as well as an array of UINavigationControllers for each Tab. The structure is similar to the iPod a

6条回答
  •  误落风尘
    2020-12-17 18:05

    For this, You just need to take UITabBar controller -

    .h File -

    UITabBarController *_pTabBarController;
    @property (nonatomic, retain) IBOutlet  UITabBarController *_pTabBarController;
    
    .m File -
    // synthesize it 
    @synthesize  _pTabBarController;    
    
    At initial load 
    
    // You can  write one function to add tabBar - 
    
    // As you have already mentioned you have created an array , if not 
    
    _pTabBarController = [[UITabBarController alloc] init];
        NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
        UINavigationController *theNavigationController;
    
        _pController = [[Controller alloc] initStart];  
        _pController.tabBarItem.tag = 1;
        _pController.title = @"Baranches";
        theNavigationController = [[UINavigationController alloc] initWithRootViewController:_pController];
        theNavigationController.tabBarItem.tag = 1;
        theNavigationController.tabBarItem.image = [UIImage imageNamed:@"icon_branches.png"];
        [localViewControllersArray addObject:theNavigationController];
        [theNavigationController release];
    

    than you can set index as per your needs

    self._pTabBarController.selectedIndex = 0; // as per your requirements
    

提交回复
热议问题