Skip to content

8. Getting views from the controller

S4cha edited this page Jan 8, 2017 · 1 revision

Once again, this is not Stevia-related per se but since we're not generally used to writing views in code, then some explanation might be useful 🤓

It goes like this :

  1. Keeping a reference to our custom view.
  2. Loading our view instead of the bare default one by overriding loadView
class MyViewController: UIViewController {

    let myCustomView = MyCustomView() // 1

    override func loadView() { // 2
      view = myCustomView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        myCustomView.loginButton.tap(login)
    }

    func login() {
      // do something
    }
}
Clone this wiki locally