|
@@ -13,7 +13,7 @@
|
|
#import "JYExpViewController.h"
|
|
#import "JYExpViewController.h"
|
|
#import "JYMineViewController.h"
|
|
#import "JYMineViewController.h"
|
|
|
|
|
|
-@interface JYTabBarController ()
|
|
|
|
|
|
+@interface JYTabBarController ()<UITabBarControllerDelegate>
|
|
|
|
|
|
@property (nonatomic,strong)JYSearchViewController *V1;
|
|
@property (nonatomic,strong)JYSearchViewController *V1;
|
|
@property (nonatomic,strong)JYSubViewController *V2;
|
|
@property (nonatomic,strong)JYSubViewController *V2;
|
|
@@ -60,27 +60,42 @@
|
|
- (void)viewDidLoad {
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
// Do any additional setup after loading the view.
|
|
-
|
|
|
|
|
|
+ self.delegate = self;
|
|
|
|
+ self.tabBarController.tabBar.delegate = self;
|
|
[self setUpAllChildVc];
|
|
[self setUpAllChildVc];
|
|
[self setSelectedIndex:0];
|
|
[self setSelectedIndex:0];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+//判断是否跳转
|
|
|
|
+- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
|
|
|
|
+ NSLog(@"点击了第几个item:%ld",tabBarController.tabBar.selectedItem.tag);
|
|
|
|
+ if (![LXUserDefaults token]) {
|
|
|
|
+ return NO;
|
|
|
|
+ }
|
|
|
|
+ return YES;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
|
|
|
|
+ NSLog(@"点击了第几个item:%ld",item.tag);
|
|
|
|
+}
|
|
|
|
+
|
|
#pragma mark - -----------------------------------------
|
|
#pragma mark - -----------------------------------------
|
|
- (void)setUpAllChildVc
|
|
- (void)setUpAllChildVc
|
|
{
|
|
{
|
|
self.V1 = [[JYSearchViewController alloc] init];
|
|
self.V1 = [[JYSearchViewController alloc] init];
|
|
- [self setUpOneChildVcWithVc:self.V1 Image:@"icon-home" selectedImage:@"icon-home2" title:@"搜索"];
|
|
|
|
|
|
+ [self setUpOneChildVcWithVc:self.V1 Image:@"icon-home" selectedImage:@"icon-home2" title:@"搜索" tag:0];
|
|
|
|
|
|
self.V2 = [[JYSubViewController alloc] init];
|
|
self.V2 = [[JYSubViewController alloc] init];
|
|
- [self setUpOneChildVcWithVc:self.V2 Image:@"icon-home" selectedImage:@"icon-home2" title:@"订阅"];
|
|
|
|
|
|
+ [self setUpOneChildVcWithVc:self.V2 Image:@"icon-home" selectedImage:@"icon-home2" title:@"订阅" tag:1];
|
|
|
|
|
|
self.V3 = [[JYExpViewController alloc] init];
|
|
self.V3 = [[JYExpViewController alloc] init];
|
|
- [self setUpOneChildVcWithVc:self.V3 Image:@"icon-home" selectedImage:@"icon-home2" title:@"实验室"];
|
|
|
|
|
|
+ [self setUpOneChildVcWithVc:self.V3 Image:@"icon-home" selectedImage:@"icon-home2" title:@"实验室" tag:2];
|
|
|
|
|
|
|
|
|
|
self.V4 = [[JYMineViewController alloc] init];
|
|
self.V4 = [[JYMineViewController alloc] init];
|
|
- [self setUpOneChildVcWithVc:self.V4 Image:@"icon-home" selectedImage:@"icon-home2" title:@"我的"];
|
|
|
|
|
|
+ [self setUpOneChildVcWithVc:self.V4 Image:@"icon-home" selectedImage:@"icon-home2" title:@"我的" tag:3];
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -96,7 +111,7 @@
|
|
* @param selectedImage 每一个按钮对应的选中状态下的图片
|
|
* @param selectedImage 每一个按钮对应的选中状态下的图片
|
|
* @param title 每一个按钮对应的标题
|
|
* @param title 每一个按钮对应的标题
|
|
*/
|
|
*/
|
|
-- (void)setUpOneChildVcWithVc:(UIViewController *)VC Image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title
|
|
|
|
|
|
+- (void)setUpOneChildVcWithVc:(UIViewController *)VC Image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title tag:(NSInteger)current_tag
|
|
{
|
|
{
|
|
JYNavigationController *nav = [[JYNavigationController alloc] initWithRootViewController:VC];
|
|
JYNavigationController *nav = [[JYNavigationController alloc] initWithRootViewController:VC];
|
|
UIImage *myImage = [UIImage imageNamed:image];
|
|
UIImage *myImage = [UIImage imageNamed:image];
|
|
@@ -109,7 +124,7 @@
|
|
VC.tabBarItem.selectedImage = mySelectedImage;
|
|
VC.tabBarItem.selectedImage = mySelectedImage;
|
|
VC.tabBarItem.title = title;
|
|
VC.tabBarItem.title = title;
|
|
// VC.navigationItem.title = title;
|
|
// VC.navigationItem.title = title;
|
|
-
|
|
|
|
|
|
+ VC.tabBarItem.tag = current_tag;
|
|
[self addChildViewController:nav];
|
|
[self addChildViewController:nav];
|
|
}
|
|
}
|
|
|
|
|