Syed e Hussaini Syed e Hussaini - 7 days ago 6
Objective-C Question

UITabBarController is running parallel with my splashsceen

I have a

UITabBarController
container 4 view controllers and two other view controllers as
SplashScreenVC
and
LoginScreenVC
as i have set
UINavigationViewController
as root view controller and initiate splash screen with the help of navigation controller in my storyboard but when i actually run the app tabBarController and splash screen both run simultaneously. I want to load all of the views of the tab bar to be load after the splash screen and submission of login details.
Here is my code where i set root view controller.

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

HomeViewController *homeVC = [[HomeViewController alloc]init];
homeVC.title = @"Home";

NotificationViewController *notificationVC = [[NotificationViewController alloc]init];
notificationVC.title = @"Notifications";

ProfileViewController *profileVC = [[ProfileViewController alloc]init];
profileVC.title = @"Profile";

SelfiesCollectionViewController *selfiesCollectionVC = [[SelfiesCollectionViewController alloc]init];
selfiesCollectionVC.title = @"Selfie Collection";

homeVC = [storyBoard instantiateViewControllerWithIdentifier:@"HomeViewController"];

profileVC = [storyBoard instantiateViewControllerWithIdentifier:@"ProfileViewController"];

notificationVC = [storyBoard instantiateViewControllerWithIdentifier:@"NotificationViewController"];

selfiesCollectionVC = [storyBoard instantiateViewControllerWithIdentifier:@"SelfiesCollectionViewController"];



self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController = [storyBoard instantiateViewControllerWithIdentifier:@"UITabBarController"];
self.tabBarController.viewControllers = @[homeVC,notificationVC,profileVC,selfiesCollectionVC];


UINavigationController *navigationVC = [[UINavigationController alloc]init];
navigationVC = [storyBoard instantiateViewControllerWithIdentifier:@"UINavigationController"];


[self.window setRootViewController:navigationVC];

Answer

You should not alloc and init your tabBarController before or the need. In your you need to make a public method like below. Remove the allocation and initiation of tabBarController from application launchWithOption method

-(void)userDidLoggedIn{
     self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController = [storyBoard instantiateViewControllerWithIdentifier:@"UITabBarController"];
self.tabBarController.viewControllers = @[homeVC,notificationVC,profileVC,selfiesCollectionVC];
[self.window setRootViewController:self.tabBarController];

}

Now simply call this method on the success of login button like this..

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate userDidLoggedIn];