Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use performSegueWithIdentifier: sender:? [duplicate]

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

like image 342
OLZ1 Avatar asked Aug 31 '13 17:08

OLZ1


2 Answers

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!

like image 123
ThisDarkTao Avatar answered Sep 30 '22 17:09

ThisDarkTao


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

like image 44
DerWOK Avatar answered Sep 30 '22 17:09

DerWOK