0

I have two tab bars in order to have effect like the one shown in Question of Sliding UITabBarItems in UITabBarController

Instead of an arrow, I am trying to use tab bar item at last index to show another tab bar, and hiding the current tab bar. I am adding second tab bar programmatically in viewDidLoad. Problem is that my second tab bar is not showing up on when last tab bar item is tapped. What I have done is:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabControler.view.frame = self.view.frame;
    self.tabControler.delegate = self;
    self.secondTabBarSelected = NO;

    self.secondTabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 431, 320, 49)];
    self.secondTabBar.hidden = YES;
    self.secondTabBar.delegate = self;
    self.secondTabBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [self.tabControler.view addSubview:secondTabBar];

    [self.view addSubview:tabControler.view];
    NSLog(@"children of tabcon: %@",[tabControler.view subviews]); //Here second tab bar added with correct frame
}

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (!self.secondTabBarSelected) {
        NSLog(@"first tab bar");
        if([[tabBarController viewControllers] indexOfObject:viewController] == 3)
        {
            self.firstTabBar.hidden = YES;
            self.secondTabBar.hidden = NO;

        }
    }
}
4

1 に答える 1

0

タブバーがnibファイルに存在するときに明示的に割り当てていたため、タブバーが表示されないことがわかりました。代わりに、フレームを設定するだけです。私の修正したコードは次のとおりです。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabControler.view.frame = self.view.frame;
    self.tabControler.delegate = self;
    self.secondTabBarSelected = NO;

    self.secondTabBar.frame = self.firstTabBar.frame;
    self.secondTabBar.hidden = YES;
    self.secondTabBar.delegate = self;
    NSLog(@"viewdidload frame: %@",secondTabBar.frame);

    self.secondTabBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [self.tabControler.view addSubview:self.secondTabBar];
    NSLog(@"viewdidload frame: %@",secondTabBar.frame);


    [self.view addSubview:tabControler.view];
}

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{

        NSLog(@"first tab bar - controller");
        if([[tabBarController viewControllers] indexOfObject:viewController] == 3)
        {
            self.firstTabBar.hidden = YES;
            self.secondTabBar.hidden = NO;
            self.secondTabBarSelected  = YES;
        }

}
于 2012-12-21T10:14:17.247 に答える