Search code examples
iosobjective-cuistoryboarduistoryboardsegue

ios: different segue to another view depending on the segue used in the previous view


Apologies, if this is a little unclear - I'm a noob when it comes to iOS programming. Here's the scenario:

I've got a LogInView, a CategoryView, a CheckerView, a WalkthroughView, and a LandingPageView.

The user starts at LogInView, and depending on the app's bluetooth state, and whether or not the user has been registered, either goes to:

  • CheckerView (Registered, Bluetooth Off)
  • LandingPageView (Registered, Bluetooth On)
  • CategoryView (Unregistered)

If the user hits CategoryView, depending on the state of his bluetooth connection, he goes to either (this part, so far, works okay):

  • WalkthroughView (Bluetooth on)
  • CheckerView (Bluetooth off)

The catch is that CategoryView will always go through WalkthroughView, regardless of whether or not bluetooth is on. So, here's what my storyboard looks like:

A right hot mess

A right hot mess, I know. Since both LogInView and CategoryView can, at some point, go into CheckerView, I need a way to check which of the segues was used, such that:

  • CheckerView will always go into LandingView if the previous view was LogInView, and
  • It will always go into WalkthroughView if the previous view was CategoryView.

I'm vaguely aware of a prepareForSegue function, but I've no idea yet how to use it, nor where to put it (from the previous page, or on the receiving page?)

Any suggestions? Thanks.


Solution

  • It sounds like you're testing conditions to determine where you'll segue. If that's the case, perhaps you could test conditions (registered/unregistered, Bluetooth enabled/disabled). Based on the various conditions, you could use performSegueWithIdentifier to determine where to go next and set up the next ViewController in prepareForSegue using the a segue identifier, rather than "looking back" to see where you came from.