Help with View switching in Xcode using storyboards

Discussion in 'iOS Programming' started by Ryute, Jul 22, 2012.

  1. Ryute macrumors newbie

    Jul 22, 2012
    I made a log-in screen that once you press the button to log-in and it authenticates the user name and password. What I want to do it switch to a different view after the authentication is completed. I am usign a storyboard for this application adn I have set it up so that the log-in button does a modal seque but it doesn't switch the view. I tested this with a sample button and all it does it switch the view back to the same view and refreshes the view. What do I need to add in order for my funtion to switch from my ViewController View (the main view) to the next view (RootViewController). I have a navigationController and an object created fromt he ViewController class but I don't know how to use them in order to switch views.

    Can anyone point me in the right direction? I can provide more information or sample code if needed.

    I am so confused when it comes to view switching...

    Thanks in advance!
  2. iJustinCabral macrumors member


    Jul 8, 2012
    Is your main view embeded in a navigation controller?

    Also, embed your next view in the navigation controller, then Control+drag from your button to the nav controller for the next view.

    Atleats thats what I do, and its always worked.

    Lemme know if this helps.
  3. Ryute thread starter macrumors newbie

    Jul 22, 2012
    How do I embed it in a navigiation controller? Do you mean through the storyboard or through code in the view controller? Does the ctrl+drag work if you already have your button doing various other functions that need to execute before the view switches?
  4. PBG4 Dude macrumors 68020

    PBG4 Dude

    Jul 6, 2007
    To embed your view in a Navigation Controller, go to your storyboard. Then click on the view controller to embed. Then go up to the menubar and go:
    Editor --> Embed In --> Navigation Controller. not sure if this is what you need, but this is how to do it.
  5. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Step 1: Quit Xcode.
    Step 2: Make a complete backup of the current project.
    Step 3: Make changes to see what happens.

    If Step 3 doesn't produce the desired results, then delete the project and get the backup made in Step 2.
  6. PBG4 Dude macrumors 68020

    PBG4 Dude

    Jul 6, 2007
    couldn't you use snapshots or git to make this easier?

    I did delete the beginning of a project and start over last week because something in my Storyboard was causing a Segue to bomb. Spent about 2 hours trying to correct it before blowing it away and rebuilding it in 15 minutes LOL.
  7. Ryute, Jul 23, 2012
    Last edited: Jul 24, 2012

    Ryute thread starter macrumors newbie

    Jul 22, 2012
    I embeded the main view to the navigation controller and it didn't change anything. I was thinking of trying this function but it gives me an error saying:

    [UIStoryboardModalSegue rootViewController]: unrecognized selector sent to instance

    Here is my function:
    -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
        if ([[segue identifier] isEqualToString:@"Enter"]) 
            // Get reference to the destination view controller 
          EDIT://  ViewController *vc = [segue rootViewController]; 
    And the function call:

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

    Am I missing something? Or am I doing this wrong? I feel like I am so close...

    I got rid of the code withing the prepare function which got rid of the error and all it does is loop back into the same view. In the storyboard I have my main view linked to the next view with the identifier "Enter" but I still get send back to the same view.


    Problem was fixed when I created a new file and redid my views. I guess the first storyboard was buggy. Thanks to everyone who replied.

    Please close this thread.

Share This Page