首页 > 移动平台 > 详细

IOS 点击tabbaritem跳转到一个新界面,且隐藏tabbar

时间:2014-12-04 12:08:37      阅读:862      评论:0      收藏:0      [点我收藏+]

先自定义一个UITabbarController,用于Storyboard中

bubuko.com,布布扣

再在MyTabbarController中实现protocol

@interface MyTabbarController : UITabBarController <UITabBarControllerDelegate>

@end
再实现代理里面的方法

@implementation MyTabbarController

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    NSLog(@"shouldSelectViewController  %@", tabBarController.selectedViewController);
    if (viewController.tabBarItem.tag == 100) {
        DiaryViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:DIARY_VC_ID];
        [((UINavigationController *)tabBarController.selectedViewController) pushViewController:vc animated:YES];
        return NO;
    }
    return YES;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.delegate = self;
    }
    return self;
}
@end
在要监听的tabbaritem跳转的viewcontroller中(比如点击一个item隐藏tabbar,而且有返回按钮)

则找到该tabbar,我的是父控件的tabbar,所以

- (void)viewWillAppear:(BOOL)animated {
    self.parentViewController.tabBarController.tabBar.hidden = YES;
}
点击返回按钮后回到开始所选中的tabbaritem

- (void)viewWillDisappear:(BOOL)animated {
    self.parentViewController.tabBarController.tabBar.hidden = NO;    
}






IOS 点击tabbaritem跳转到一个新界面,且隐藏tabbar

原文:http://blog.csdn.net/fanxiaoxuan1234/article/details/41721635

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!