Tabbar in Second View

前端 未结 3 1400
北恋
北恋 2020-12-07 06:04

I have an activation page in my app, which is mandatory for every user to activate the app. Once the app is activated, the user moves to the tabbed bar view.

I have

3条回答
  •  醉梦人生
    2020-12-07 06:48

    Hey make your tabBarController's property in appDelegate and assign all ViewController there then call your tabBarController from yourViewController

    in AppDelegate.h

    @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
    @property (retain, nonatomic) IBOutlet UITabBarController *tabBarController;
    

    in AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        [self makeTabBar];
    
        [self addInitialVIew];
    
        [self.window makeKeyAndVisible];
    
        return YES;
    }  
    
    
    -(void)makeTabBar
    {    
        tabBarController = [[UITabBarController alloc] init];
        tabBarController.delegate=self;
        FirstViewController *firstVC =[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];    
    
        UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
        firstNC.tabBarItem.title=@"Profile";
        firstVC.tabBarController.tabBar.tag = 0;
    
    
        SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    
        UINavigationController *SecondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];    
        SecondNavController.tabBarItem.title = @"Search";
        secondVC.tabBarController.tabBar.tag = 1;
    
    
        NSArray *viewControllers =[[NSArray alloc]initWithObjects:firstNC,SecondNavController, nil];
        [tabBarController setViewControllers:viewControllers animated:NO];   
    }
    
    -(void) addInitialVIew
    {    
        InitialViewController *initialViewController = [[InitialViewController alloc]initWithNibName:@"InitialViewController" bundle:nil];
        navigationController = [[UINavigationController alloc]initWithRootViewController:ViewController];
        [self.window addSubview:navigationController.view];
    }
    

    Now in InitialViewController you can add yourTabBar and remove InitialViewController

    - (IBAction)switchToTabBarBtnPress:(id)sender
    {
        AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
        [[[appdelegte navigationController] view]removeFromSuperview];
    
        [[appdelegte window]addSubview:[[appdelegte tabBarController]view]];
    
        [[appdelegte tabBarController]setSelectedIndex:0];
    }
    

    And Follow my answer

    Answer

提交回复
热议问题