Presenting a view for the first time in appDelegate

后端 未结 4 1181
遥遥无期
遥遥无期 2020-12-22 07:21

The goal:

When my app starts up - I need it to display a view before it gets to the \"Home\" screen. Its a tab bar application and this view is not

相关标签:
4条回答
  • 2020-12-22 08:01
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
    
    
        if(!isAgreementAccepted)
        {
    
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDD"];
        self.window.rootViewController=vc;
        }
    
        return YES;
    }
    

    If agreement is not accepted set the T&C viewController as rootViewController when user click the accept button then set the TabBarviewController as root.

    u can access the widow object through application delegate any where

    [[[UIApplication sharedApplication]delegate] window].rootViewController=tabViewController.
    
    0 讨论(0)
  • 2020-12-22 08:07

    If Tabbarcontroller is your root viewcontroller, then using below code will resolve the issue in your appdelegate.

     -(void)showCountrySettings
      {
    
         if (self.termsHaveBeenAccepted){
    
        BBCounterySettingsViewController *countrySettings = [[BBCounterySettingsViewController alloc]initWithNibName:@"View" bundle:nil];
    
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"];
        UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    
        [tabBarController presentModalviewcontroller:vc animated:YES completionblock:nil];
      }
    
    0 讨论(0)
  • 2020-12-22 08:14

    Change the rootviewcontroller of window programaticaly

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
       UIStoryboard *aStoryBoard=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
       UITabBarController *aTabCtrl=[aStoryBoard instantiateViewControllerWithIdentifier:@"Tab"];
       FirstVC *aFirstCtrl=[aStoryBoard instantiateViewControllerWithIdentifier:@"First"];
    
       if(self.termsHaveBeenAccepted)
          self.window.rootViewController=aFirstCtrl;
       else
          self.window.rootViewController=aTabCtrl;
       return YES;
    }
    

    This will definitely work I have tested.

    0 讨论(0)
  • 2020-12-22 08:24

    add your viewcontroller superview of tabbarcontroller as first time else call tabbarcontroller alone

    0 讨论(0)
提交回复
热议问题