How to work and switch multiple View Controllers via code?

2

Without using a button to switch between views, everything happens via code.

I already have the part that validates the credentials of the user, but when they are correct I do not know how to display the second View that contains a UIWebView .

Any tips?

    
asked by anonymous 16.12.2015 / 02:48

4 answers

3

Good afternoon, do you have two screens correct? and you want it after the valid user goes to your other right view? Go to your Credential View, Hold and Drag the Yellow Ball with Control and place Show,

Follow the screen with an Identifier, put the name you want,

After the code that the user logs in or makes the credentials just put below the code:

 self.performSegueWithIdentifier("NomeDoSeguimento", sender: self)

A simple example is the Login of facebook, after it logs, just put down the perfomrSegueWithIdentifier, that it goes to the view that you put the Segue ..

Do not forget to create follow-up!

In my case it's showLogin! With this code you can send the user to the View you want as long as you put the right name in the Identifier!

I hope I have helped!

    
17.12.2015 / 20:54
3

You can do it this way:

First you need to give an id to your View Controller destination

This can be done this way

NowyoucanusethisidtogettotheViewController

YoushouldusethiscodeintheSwiftfileofyourSourceViewtogototheDestinationViewwhenyouwanttoswitchtothisViewController.

Swift

varviewController:UIViewController=self.storyboard!.instantiateViewControllerWithIdentifier("View2") //View 2 é o id que vc especificou na sua View Controller
         self.presentViewController(viewController, animated: true, completion: { _ in })

This way it goes to the destination view.

    
31.03.2016 / 15:35
2

If you do not want to use performSegue, you can do the following:

let newView = SecondViewController()
self.presentViewController(newView, animated: true, completion: nil)

This method does not require you to manipulate the storyboard.

    
29.12.2015 / 18:44
1

You can use the delegate method of UITextField :

textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool

To check the characters entered in the field or fields, they are the same as the data registered by a user, if it is, go to the second view or another one specifies.

    
16.12.2015 / 15:26