13

I am a new iOS developer and I am currently building a game for the iPhone, and I am writing it in Objective-C.

This question will probably be very easy to answer but I couldn't find it anywhere else. I am using storyboards in this app and I was using them fine when a user pressed a button to go to the next storyboard, however for this when the segue needs to occur automatically I am completely stumped as to how to achieve this.

I want to have a logo appear for about five seconds when the app is launched, then the main menu should appear. I am trying to use performSegueWithIdentifier:sender: to achieve this, however I have browsed apple's documentation and it doesn't really answer my question on how this method is used.

I know what this method is used for, just not what code I need to type to correctly use it.

Also if I am using the completely wrong method, or there's a much easier way to achieve what I am trying to do, that would be much appreciated. Any help is useful. Thanks in advance

OLZ1
  • 185
  • 1
  • 2
  • 9

2 Answers2

42

To make a kind of 'splash screen' for your app, just create the view for it in your Storyboard and set it as the entry point (or root of a Navigation Controller etc). Create a segue like you have previously, except drag a segue from the 'Splash' view controller, to the 'Main Menu' controller. With the segue selected, set its Identifier in the Attributes inspector to ShowMainMenu.

Create a method in the 'Splash' view controller that performs the segue:

- (void)showMainMenu {
    [self performSegueWithIdentifier:@"ShowMainMenu" sender:self];
}

In the 'Splash' view controller's viewDiDLoad method, add:

[self performSelector:@selector(showMainMenu) withObject:nil afterDelay:5.0];

There you have it!

ThisDarkTao
  • 1,062
  • 10
  • 27
1

This does not answer your segue question. But it solves your root problem of displaying a splash screen in an ios app:

What you describe (and what many app show) is a "Launch Image". No need to code it at your own. In Xcode just go to the settings of your target, then "Summary" and add some launch images.

You have to provide launch images for different display resolutions and devices.

If you want to show the image for at least 5 seconds, see here: increase launch image time on xcode

Community
  • 1
  • 1
DerWOK
  • 1,061
  • 9
  • 13
  • An application's launch image is actually supposed to be a screenshot of the apps interface after it has loaded, giving the illusion the app loads fast. Sleeping the main thread to make a launch image display for longer is smelly. More info can be found here: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html#//apple_ref/doc/uid/TP40006556-CH14-SW5 – ThisDarkTao Aug 31 '13 at 20:20
  • Yeah, tried it out and it provided a really slow experience, not a great idea really :/ The launch image idea is a lot better, will try that out now. – OLZ1 Aug 31 '13 at 21:15
  • @ThisDarkTao your suggestion really helped improve the overall experience :) – OLZ1 Aug 31 '13 at 21:20