How to work and switch multiple View Controllers via code?

Asked

Viewed 874 times

2

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

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

Any hint?

4 answers

3

You can do it this way:

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

It can be done this way

inserir a descrição da imagem aqui

Now you can use this id to get to the View Controller

You must use this code in the Swift file of your source View to go to the target View when you want to switch to this View Controller.

Swift

var viewController: 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 he goes to the destination View.

  • Thank you very much for your reply.

3

Good afternoon, you have two correct screens? and you want after the user validate go to your other view right? Go to your Credential View, Hold and Drag the Yellow Ball with Control and Put Show,

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

After the code 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 login, just put down the profile..

don’t forget to create the following!

Identifier

that in my case is showLogin! With this code you can send the user to the View as long as you put the right name in the Identifier!

I hope I’ve helped!

  • 1

    Thank you very much for your reply, I was able to resolve.

2

If you don’t 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.

  • Thank you very much for your reply.

1

You can use the method delegate of UITextField:

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

To check the characters typed in the field or fields, are equal to the data recorded by a user, if they are, go to the second View or other specifics.

  • 1

    Thank you very much for your reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.