1

I want to create a segue that takes me from one view controller to another if a condition is met without the use of a button. This segue should take place once the application loads for the firs time. It would look something like this:

if(condition){
   //perform segue
}

I just don't know how to actually perform the segue. How could I do this?

Ryan Tobin
  • 214
  • 2
  • 13
  • Does [this](http://stackoverflow.com/questions/9176215/understanding-performseguewithidentifier) answer your question? – zneak Jul 09 '15 at 15:15
  • try this link very hope ful for you , the link http://stackoverflow.com/questions/29294160/how-to-create-a-segue-in-ios-without-having-an-associated-ui-element/29294298#29294298 – Anbu.Karthik Jul 09 '15 at 15:20
  • Yes it is helpful however I do not know what kind of segue I should use? @Anbu.Karthik – Ryan Tobin Jul 09 '15 at 16:17
  • Your edit makes it an X-Y question, because you do not need a segue to choose the initial view controller. – Sergey Kalinichenko Jul 09 '15 at 16:22
  • Well I want a segue to the other view only if a condition is met. If that condition is not met, then it stays on the initial view – Ryan Tobin Jul 09 '15 at 16:23
  • @dasblinkenlight that worked. If you make it an answer, I can select it as correct – Ryan Tobin Jul 09 '15 at 16:41

1 Answers1

4

You can do it using performSegueWithIdentifier:sender: method:

if (condition) {
    [self performSegueWithIdentifier:@"mySegue" sender:self];
}

The snippet above assumes the context of an instance method in a class that defines a segue with identifier "mySegue".

This segue should take place once the application loads for the firs time.

You do not need a segue for situations when the application loads. Instead, you need to set the initial view controller programmatically.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 675,664
  • 71
  • 998
  • 1,399
  • how do I define the segue Identifier to be mySegue or whatever I want it to be – Ryan Tobin Jul 09 '15 at 15:17
  • When I looked at that website, you must use a button for the segue, but I do not want to use a button – Ryan Tobin Jul 09 '15 at 15:32
  • I do not think we are on the same page. I am basically trying to do it all programmatically. – Ryan Tobin Jul 09 '15 at 15:37
  • 1
    Note that the segue is not defined in the class, but the storyboard. Create the segue to go from the first view controller to the second, by selecting the first and control-dragging to the second. – Mike Taverne Jul 09 '15 at 15:40
  • It doesn't let me do that unless I am using a button – Ryan Tobin Jul 09 '15 at 15:43
  • It gives me the following: – Ryan Tobin Jul 09 '15 at 15:45
  • My Application[14561:3988910] Warning: Attempt to present on whose view is not in the window hierarchy! – Ryan Tobin Jul 09 '15 at 15:45
  • What kind of segue should it be? Should it be like modal reveal view controller or what? – Ryan Tobin Jul 09 '15 at 15:48
  • Thats not what I want. Basically when the application is launched, If a certain condition is met, I need a segue that takes me from one view to the other, with no buttons or anything. To the users eyes it would look as if that view is the first view – Ryan Tobin Jul 09 '15 at 16:12