您的位置:首页 > 移动开发 > IOS开发

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

2014-12-04 11:38 666 查看
先自定义一个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;
}

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: