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

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


再在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;    
}

点击以上图片中的“日记”时,则







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值