0

I am fairly new to navigation view controllers and stacks in iOS. Please help me with this, tried searching for a long time couldn't find anything relevant.

I have a LoginViewController, a SWRevealViewController for side menu operation, a FirstViewController (the first one in navigation stack) and a SecondViewController (second in navigation stack).

I have to do the following in LoginViewController, assume login and found are two boolean variables:

if (login && !found) {
//redirect to FirstViewController : the following works
[self presentViewController:swReveal animated:NO completion:nil];
}
else if (login && found) {
//redirect to SecondViewController
}

Please help me fill the else if. Really appreciate your time!

Arpit Goel
  • 163
  • 1
  • 16
  • 1
    So where do you actually use the FirstViewController and why do you need it if you're not presenting it? Maybe include a screenshot of your storyboard to make what you're asking for more clear. – RJiryes Nov 03 '14 at 08:47
  • I need the FirstViewController if my found variable is false. The specific application is that if the phone finds a beacon nearby then found=YES, then it redirects to the SecondViewController. The SecondViewController is a DetailView Cell of the FirstViewController which is a tableView. – Arpit Goel Nov 03 '14 at 09:02

1 Answers1

0

So based on what I understood from your comments, FirstViewController is a subclass of TableViewController and SecondViewController is the DetailView.

So based on that, the best approach for "redirecting" to the DetailView (SecondViewController), would be creating a segue on the Storyboard, and then calling that segue programatically once the FirstViewController is loaded (in its viewDidLoad)

On both cases you would first show the FirstViewController and then depending on the if statement, you would either stay or go to the SecondViewController.

So first step: Create the segue from the Storyboard, and give it an identifier.

Second: Perform that segue programatically when the FirstViewController is loaded (and of course, the if statement is valid) by using:

[self performSegueWithIdentifier: @"MySegue" sender: self];

More on that subject:

Alternative ways to push view controllers with storyboard programmatically

Creating a segue programmatically

Community
  • 1
  • 1
RJiryes
  • 951
  • 10
  • 25
  • Thanks a lot for your answer.. So that means I have to go through the FirstViewController right ? I cannot directly go to SecondViewController.. ? Ideally I would want to do that. According to this in LoginViewController, I set some FirstViewController's variable to true if beacon is found, and in viewDidLoad of FirstViewController, I performSegue if the variable is true. – Arpit Goel Nov 03 '14 at 10:31
  • Yup, I think thats the way to do it if you want to go back to the FirstViewController, as it is the first on the stack. – RJiryes Nov 03 '14 at 10:34