导航时隐藏选项卡栏

时间:2012-11-27 10:10:51

标签: iphone ios xcode uitabbarcontroller

我默认选择My Project中的四个选项卡首选选项卡是Home Class当用户通过选择任何选项卡导航到任何其他类时,我必须检查用户是否在我的应用程序中登录的时间然后他将导航到他选择的课程,他移动到登录屏幕。

 if(appDelegate.sessionId==0)
            {

                Login *objLogin=[[[Login alloc] initWithNibName:@"Login" bundle:nil] autorelease];

                [self.navigationController pushViewController:objLogin animated:YES];

            }
            else 
            {
                CreatePoll *objLogin=[[[CreatePoll alloc] initWithNibName:@"CreatePoll" bundle:nil] autorelease];
                [self.navigationController pushViewController:objLogin animated:YES];

            }

}

如果我导航到登录屏幕,我的标签栏会被隐藏,当我调试代码时,我知道创建投票类也会在后台调用我检查这个link以显示隐藏的标签栏但是无法获得成功。请帮助我们,我在过去3天里遇到了这个问题。 无法在登录屏幕中看到我的标签栏。请帮助

1 个答案:

答案 0 :(得分:1)

只需在viewWillAppear:方法中编写此代码即可隐藏并显示UITabBar

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.tabBarController.tabBar setHidden:NO];

<强>更新

AppDelegate.m文件中发布这些方法,当您想要显示和隐藏Tabbar时,创建AppDelegate对象并调用此方法

- (void) hideTabBar:(UITabBarController *) tabbarcontroller {

    int height = 480;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    for(UIView *view in tabbarcontroller.view.subviews) {
        if([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
        } 
        else {
            [view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
        }
    }
    [UIView commitAnimations];
}

- (void) showTabBar:(UITabBarController *) tabbarcontroller {

    int height = 480;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; 

    for(UIView *view in tabbarcontroller.view.subviews) {

        if([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];            
        } 
        else {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
        }
    }    

    [UIView commitAnimations];
}