Ios: How to open a tab bar controller from ViewController using StoryBoards

I do this and want to open the tab bar controller from the login page if it is the first time, and if it is already connected, go through LoginPage and open the tab bar after Spalsh

means that if the user has landed in the application, then it should be so 1. Splash 2. Login page 3. If the entry to the control panel of the "Control Panel" tab with 4 tabs is successfully opened

if the user has already registered 1. Splash 2. Tab bar controller

enter image description here

I am trying to open a Tab panel controller through the following code in the ViewDidLoad method

UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:@"TripMapViewer"]; tbc.selectedIndex=0; [self presentViewController:tbc animated:YES completion:nil]; 

but he gives an error

2014-02-06 19: 55: 43.849 ProjNew [1065: 907] - [TripMapViewer setSelectedIndex:]: unrecognized selector sent to instance 0x1d5600b0

and if I remove tbc.selectedIndex = 0; , it will not do anything and will remain on the Splash screen, like this

 UITabBarController *lbc = [self.storyboard instantiateViewControllerWithIdentifier:@"TripMapViewer"]; [self presentViewController:lbc animated:YES completion:nil]; 

suggest how to open the tab bar from View Controller

+7
ios objective-c iphone ipad xcode5
source share
3 answers

TripMapViewer seems to be the Storyboard ID some tab, not UITabBarController , please make sure it will work

as in MainTabBar Storyboard ID UITabBarController code below and it works fine

 UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainTabBar"]; tbc.selectedIndex=0; [self presentViewController:tbc animated:YES completion:nil]; 
+18
source share

You do not need a screen controller if you are not animating something. This example uses NSUserDefaults to remember whether it was the first to log in or not.

In your application, add the following:

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; if(![[NSUserDefaults standardUserDefaults] dictionaryForKey:@"someKey"]){ UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"registerViewController"]; self.window.rootViewController = viewController; } else { UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"mainViewController"]; self.window.rootViewController = viewController; } [self.window makeKeyAndVisible]; return YES; } 

If you decide that you should have a viewcontroller for the splash screen, you can put the same code there.

+1
source share

The fact that the created VC is not a TabBarController explains the crash. The code requests a storyboard for regular vc, passes it as a UITabBarController , and then sends it a setSelectedIndex message: it is not implemented because it is not a tab bar controller.

At least the first step in where you want to go is to add the identifier in the storyboard to the tab bar controller (for which TripMapViewer is one of the tabs). Then create an instance, and the accident should disappear.

At the development level, see my question and answer here on how to make login and splash.

+1
source share

All Articles