Cocoa-Touch: How to Change View After Input Validation?
I have a single-view application that takes in a username and a password and validates it with the server. After the credentials are validated, I would like the application to go to a different view, which will show some other data.
I only know how to switch views when I have a button (that is, by dragging it to the secondary view and selecting what kind of segue I want to use). But how do I change the view after the credentials are validated?
To give you a more clear idea, here is how my app currently functions:
Text is entered into two fields. Pressing the "Login" button (or the 'done' button on the keyboard) calls a method that validates the entered credentials. If the credentials are valid, then the add should move on. Otherwise, it will pop up a notification saying that the credentials are invalid.
I have everything completed and working. I just need to know how to change the view in the validation method after the given credentials are validated.
There are a number of ways to achieve this; the technique you choose should depend on if you want the validating view controller to "stay around" after you move on. If you want it to stick around, you can actually do it in much the same manner as your storyboard segues from buttons.
In the storyboard, ctrl-drag from the first (validating) view controller to the second to create the segue. Select the segue and use the inspector panel to give it an identifier. Then in your code in the validating view controller, you can do something like this:
[self performSegueWithIdentifier:@"validCredentialsSegue" sender:self];
If you want the originating view controller to "go away", you must look into the architecture of your application flow. Perhaps you want a master view controller "above" the credential's one that is notified via delegation of the successful login and it decides what to do (maybe it's view is the destination view anyway...). Otherwise, I think in the old days people fussed around with setting the window's rootViewController property. I'm confident there are better techniques, though.