Search code examples
objective-csdkinterface-builderuistoryboardsegue

Some problems with segue and splash screen


I am trying to make a splash screen, but tutorial says, I should make a segue from StatusBar of the ViewController, where my Splash screen is, to the next one ViewController, that is a start page. This tutorial is obviously too old, because I have the last XCode. How should it be done?


Solution

  • Go to the storyboard, insert a UINavigationController and connect it to the UIViewController you want to make your splash screen. If you haven't created any, you can use the UIVewController that will be inserted with the UINavigationController you drag into your storyboard. Now create new classes of type UIViewController and set them as Custom Class for the splash screen in the storyboard (inside the Identity inspector). Into the .m file you have to insert following code to perform a segue to another UIViewController:

    - (void)viewDidLoad{
    
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        [self performSelector:@selector(goToLandingPage)
                   withObject:nil
                   afterDelay:3.0f];
    }
    
    
    - (void)goToLandingPage{
    
        [self performSegueWithIdentifier:@"landingpage" sender:self];
    }
    

    Next you have to create a second UIViewController inside thestoryboardand drag a segue from the splash to the nextUIViewController(don't forget to pressSTRG, and zoom out). Click on thissegueand insert the identifier (in theAttributes Inspector` on the right), in my case landingpage.

    Everytime you want to perform a segue programmatically inside your code, you have to select the UIViewController it self inside the storyboard and drag it to the controller you want. Otherwise just use a UIButton and it will perform by click.