瀏覽代碼

同一个tabbar

apple 6 年之前
父節點
當前提交
6602a8b328

二進制
ios/JianYuIOS/JianYuIOS.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate


+ 1 - 1
ios/JianYuIOS/JianYuIOS.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -26,7 +26,7 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "JianYuIOS/AppDelegate.m"
-            timestampString = "563342618.3573509"
+            timestampString = "563344192.9196841"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "415"

+ 23 - 8
ios/JianYuIOS/JianYuIOS/JYTabBarController.m

@@ -13,7 +13,7 @@
 #import "JYExpViewController.h"
 #import "JYMineViewController.h"
 
-@interface JYTabBarController ()
+@interface JYTabBarController ()<UITabBarControllerDelegate>
 
 @property (nonatomic,strong)JYSearchViewController *V1;
 @property (nonatomic,strong)JYSubViewController *V2;
@@ -60,27 +60,42 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
-    
+    self.delegate = self;
+    self.tabBarController.tabBar.delegate = self;
     [self setUpAllChildVc];
     [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 - -----------------------------------------
 - (void)setUpAllChildVc
 {
     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 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 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 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 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];
     UIImage *myImage = [UIImage imageNamed:image];
@@ -109,7 +124,7 @@
     VC.tabBarItem.selectedImage = mySelectedImage;
     VC.tabBarItem.title = title;
     //    VC.navigationItem.title = title;
-    
+    VC.tabBarItem.tag = current_tag;
     [self addChildViewController:nav];
 }