1

I would like to ask if it's possible to show a tabbarcontroller after I showed one view controller. I've seen lots of tutorials about tabbarcontroller but they were all put in the AppDelegate using this line:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self.window addSubview:tabController.view];
[self.window makeKeyAndVisible];
return YES;}

What I would like to do is show one view controller first:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{     
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES; }

and after showing the viewController, the user will have to click a button to show another view with the TABBARCONTROLLER. If that's possible, how do I do that?

JCurativo
  • 713
  • 6
  • 17

3 Answers3

2

Yes you can... in your first controller, after some job is completed then push the Tabbar controller.

Example:-

Assuming you have TabBarController class by sub classing UITabBarController.

- (void) doSomeJob
{
  if(true)
  {
     TabBarController *aTabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];
     [self.navigationController pushViewController:aTabBarController animated:YES];
     [aTabBarController release];    
  }
}

EDITED custom tab bar :

.h file

@interface TabBarController : UITabBarController<UITabBarControllerDelegate,    UINavigationControllerDelegate> 
{
    UITabBarController *tabController;
    UINavigationController *1NavController;
    UINavigationController *2hNavController;
}

@property (nonatomic, retain) UITabBarController *tabController;
@property (nonatomic, retain) UINavigationController *1NavController;
@property (nonatomic, retain) UINavigationController *2hNavController;

.m file :

- (void)viewDidLoad
{
[super viewDidLoad];    

tabController = [[UITabBarController alloc] init];
tabController.delegate = self;
tabController.tabBar.backgroundColor = [UIColor clearColor];

//Add some tabs to the controller...
1ViewController *1ViewController = [[1ViewController alloc] initWithNibName: @"1ViewController" bundle: nil];
1NavController = [[UINavigationController alloc] initWithRootViewController:1ViewController];
1NavController.tabBarItem = [[UITabBarItem1 alloc] init];

2ViewController *aSearchViewController = [[2ViewController alloc] initWithNibName: @"2ViewController" bundle: nil];
2NavController = [[UINavigationController alloc] initWithRootViewController:2ViewController];
2NavController.tabBarItem = [[UITabBarItem2 alloc] init];

tabController.viewControllers = [NSArray arrayWithObjects: 1NavController,2NavController,nil];

[self.view addSubview:tabController.view];
}

Also you need to implement Tab bar's delegate methods accordingly....

Maulik
  • 19,348
  • 14
  • 82
  • 137
0

I had a situation with navigation controller and tab bar view controller but ur need is with view controller so i modify my code according to ur requirement.check n reply first initialize view controller and tabbar controller both in app delegate .h file & give property also like:

{
    IBOutlet FirstViewController * fvc;

    IBOutlet UITabBarController  *tabBarController;
}
@property (nonatomic, retain) IBOutlet FirstViewController * fvc;
@property (nonatomic, retain) IBOutlet UITabBarController  *tabBarController;

than in .m file set the view controller to the view as u want to set simple view controller first, like :

fvc = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];


[self.window addSubview: fvc.view];

Now in the this view controller on the particular event where u want to jump to tabbar view controller user this :

    AppDelegate_iPhone *appDelegte_iPhone=(AppDelegate_iPhone*)[[UIApplication sharedApplication]delegate];                 
[[[appDelegte_iPhone viewController] view] removeFromSuperview];
[[appDelegte_iPhone window]addSubview:[[appDelegte_iPhone tabBarController]view]];  

  [[appDelegte_iPhone tabBarController]setSelectedIndex:0];
kulss
  • 2,057
  • 1
  • 14
  • 16
0

Leave the UITabBarController as your window's root view controller. Present your other view controller as a modal view controller. Dismiss the modal view controller to reveal the tab bar controller.

Jonah
  • 17,918
  • 1
  • 43
  • 70