Code Monkey home page Code Monkey logo

ac3.2-in-depth-views-vcs's Introduction

AC3.2 In-Depth Views & View Controllers


Readings

  1. The Role of View Controllers
  2. View Controller Hierarchy

All day programmatic!


View Controllers

  1. Manages portions of your user interface
  2. Facilitates transitions between different parts of the interface

All view controllers have a strong reference to their root view, which is set up in its loadView() function. It's rather uncommon to have to override loadView, but sometimes it is done to ensure that elements are added/set properly by the time viewDidLoad is called.

Root View Controller

Every UIWindow has exactly one root view controller whose contents fill that window. The root view controller defines the initial content seen by the user... The root view controller is accessible from the rootViewController property of the UIWindow object. When you use storyboards to configure your view controllers, UIKit sets the value of that property automatically at launch time. For windows you create programmatically, you must set the root view controller yourself.

It is possible to programmatically define all elements of a storyboard in code starting from the AppDelegate:

  // embedding a UINavigationController in a ViewController
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    // instantiate the ViewController
    let rootVC: ViewController = ViewController()
    
    // Instantiate the navVC, add the rootVC
    let navigationVC: UINavigationController = UINavigationController(rootViewController: rootVC)
    
    // Define the bounds of your app's window
    self.window = UIWindow(frame: UIScreen.main.bounds)
    
    // Set your rootVC
    self.window?.rootViewController = navigationVC
    
    // Last line that is required to display content:
    self.window?.makeKeyAndVisible()
    
    return true
  }

With this portion of the code defined, we can even go into our project settings and remove our reference to our story board entirely! Congratulations, we are no longer burdened by the merge conflicts associated with storyboards... (pause for sigh of relief)...

Container View Controllers

Help to assemble and manage a hierarchy of child view controllers. Some examples include UINavigationController, UISplitViewController, UITabBarController, UIPageViewController. A container view controller's view always takes up

ac3.2-in-depth-views-vcs's People

Contributors

spacedrabbit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.