3

I'm working on a tab bar application with five items in it and I want to open the third view controller which is associated to the third tab bar item when my application launches instead of the first one which opens by default. How can I approach this?

Here's the code I'm using:

In myappdelegate.h

@property (nonatomic, retain) IBOutlet   FirstViewController *firstView;

In myappdelegate.m

[window addSubView:firstView.view];

This doesn't work.

Free light
  • 93
  • 1
  • 7

3 Answers3

11

you can use bellow code to display the 3 tab of UITabBar at first...

self.window.rootViewController = self.tabBarController;
self.tabBarController.selectedIndex = 2;
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • Thanks , I will give your answer and the other a try when I have a chance. – Free light Jan 12 '13 at 05:46
  • no problem , post comment if you get any query.. and for display 3 tab at application launch then just use this only one line after you assign tabbarcontroller as a rootviewcontroller for window... – Paras Joshi Jan 12 '13 at 05:48
  • I do not have chance to try it right now because I'm away of my desk but I will let you know if there is any issue. Thanks. – Free light Jan 12 '13 at 06:53
3

In the viewWillAppear method of that viewController set the visible tab:

self.yourTabBarController.selectedViewController = [yourTabBarController.viewControllers objectAtIndex:2];
Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
0

Use the methods above but if you want it to happen with the application launches you need to use -(void) awakeFromNib { That function is called when you press the app icon on your devices home screen. viewDidLoad is called after your Default.png has been displayed.

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195