0

我有两个标签栏,以便产生类似于在UITabBarController 中滑动 UITabBarItems 的问题中所示的效果

我试图在最后一个索引处使用标签栏项目而不是箭头来显示另一个标签栏,并隐藏当前的标签栏。我正在以编程方式添加第二个标签栏viewDidLoad。问题是当最后一个标签栏项目被点击时,我的第二个标签栏没有出现。我所做的是:

- (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 回答