I am unsure how to look at a view controller in the simulator or preview

I am building a project right now. I have built various views and started going on YouTube to create view controllers for a log in screen. Every time I run the simulator I can't see the view controller for the log in screen to see my progress, instead, it runs the views I made for the content view.

How can I display the View Controller in the preview or simulator? This log in file I am working does not show up in either and I would like to see my progress. Please let me know what is going on.

Thanks!


import UIKit



class LogInViewController: UIViewController {

    

    private let scrollView: UIScrollView = {

        let scrollView = UIScrollView()

        scrollView.clipsToBounds = true

        return scrollView

    }()

    

    private let imageView: UIImageView = {

        let imageView = UIImageView()

        imageView.image = UIImage(systemName: "message.fill")

        imageView.contentMode = .scaleAspectFit

        return imageView

    }()

    

    private let emailField: UITextField = {

        let field = UITextField()

        field.autocapitalizationType = .none

        field.autocorrectionType = .no

        field.returnKeyType = .continue

        field.layer.cornerRadius = 12

        field.layer.borderWidth = 1

        field.layer.borderColor = UIColor.lightGray.cgColor

        field.placeholder = "Enter your email address"

        field.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: 0))

        field.leftViewMode = .always

        field.backgroundColor = .white

        return field

    } ()

    

    private let passwordField: UITextField = {

        let field = UITextField()

        field.autocapitalizationType = .none

        field.autocorrectionType = .no

        field.returnKeyType = .done

        field.layer.cornerRadius = 12

        field.layer.borderWidth = 1

        field.layer.borderColor = UIColor.lightGray.cgColor

        field.placeholder = "Enter your password"

        field.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: 0))

        field.leftViewMode = .always

        field.backgroundColor = .white

        field.isSecureTextEntry = true

        return field

    } ()



    private let loginButton: UIButton = {

        let button = UIButton()

        button.setTitle("Log In", for: .normal)

        button.backgroundColor = .link

        button.setTitleColor(.white, for: .normal)

        button.layer.cornerRadius = 12

        button.layer.masksToBounds = true

        button.titleLabel?.font = .systemFont(ofSize: 20, weight: .bold)

        return button

    }()

    

    

    override func viewDidLoad() {

        super.viewDidLoad()

        title = "Log In"

        view.backgroundColor = .white

        

        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Register",

                                                        style: .done,

                                                        target: self,

                                                        action: #selector(didTapRegister))

        loginButton.addTarget(self,

                              action: #selector(loginButtonTapped),

                              for: .touchUpInside)

        

        //hitting return calls the log in function

        emailField.delegate = self

        passwordField.delegate = self

        

        

        

        // add fields subview

        view.addSubview(scrollView)

        scrollView.addSubview(imageView)

        scrollView.addSubview(emailField)

        scrollView.addSubview(passwordField)

        scrollView.addSubview(loginButton)

    }

    //lay out on screen

    override func viewDidLayoutSubviews() {

        super.viewDidLayoutSubviews()

        scrollView.frame = view.bounds

        let size = scrollView.width/3

        imageView.frame = CGRect(x: (scrollView.width-size)/2,

                                 y: 20,

                                 width: size,

                                 height: size)

        emailField.frame = CGRect(x: 30,

                                  y: imageView.bottom + 10,

                                  width: scrollView.width - 60,

                                  height: 52)

        passwordField.frame = CGRect(x: 30,

                                  y: emailField.bottom + 10,

                                  width: scrollView.width - 60,

                                  height: 52)

        loginButton.frame = CGRect(x: 30,

                                   y: passwordField.bottom + 10,

                                   width: scrollView.width - 60,

                                   height: 52)

    }

    

    @objc private func loginButtonTapped() {

        

        emailField.resignFirstResponder()

        passwordField.resignFirstResponder()



        guard let email = emailField.text,

                let password = passwordField.text,

              !email.isEmpty, !password.isEmpty, password.count >= 6 else {

                  return

              }

    }

    

    func alertUserLoginError() {

        let alert = UIAlertController(title: "Didn't quite crack the code",

                                      message: "Please enter all info to log on",

                                      preferredStyle: .alert)

        alert.addAction(UIAlertAction(title: "Dismiss",

                                      style: .cancel,

                                      handler: nil))

        present(alert, animated: true)

    }

    

    @objc private func didTapRegister() {

        let vc = RegisterViewController()

        vc.title = "Create Account"

        navigationController?.pushViewController(vc, animated: true)

    }

}



extension LogInViewController: UITextFieldDelegate {

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {

        

        if textField == emailField {

            passwordField.becomeFirstResponder()

        } else if textField == passwordField {

            loginButtonTapped()

        }

        return true

    }

Add a print to be sure you load the view:

    override func viewDidLoad() {
        super.viewDidLoad()

        print("Log In")

Note: when you paste code, use Paste and Match Style, to avoid all the extra blank lines that make reading more difficult.

I am unsure how to look at a view controller in the simulator or preview
 
 
Q