IOS 點選tabbaritem跳轉到一個新介面,且隱藏tabbar
阿新 • • 發佈:2019-02-15
先自定義一個UITabbarController,用於Storyboard中
再在MyTabbarController中實現protocol
@interface MyTabbarController : UITabBarController <UITabBarControllerDelegate>
@end
再實現代理裡面的方法
在要監聽的tabbaritem跳轉的viewcontroller中(比如點選一個item隱藏tabbar,而且有返回按鈕)@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
則找到該tabbar,我的是父控制元件的tabbar,所以
- (void)viewWillAppear:(BOOL)animated {
self.parentViewController.tabBarController.tabBar.hidden = YES;
}
點選返回按鈕後回到開始所選中的tabbaritem
- (void)viewWillDisappear:(BOOL)animated { self.parentViewController.tabBarController.tabBar.hidden = NO; }
點選以上圖片中的“日記”時,則