Adding a New UIViewController

As the name suggests, UIViewControllers are objects that control a view. The UIViewController object stores the UIView it manages inside the view attribute. However, we generally don’t use addSubview: to add this particular view to the screen; instead, various methods will often take the entire UIViewController object and adjust the view as necessary before adding it to a hierarchy.

Let’s get started with a small project to see how UIViewController works, and you’ll see what I mean. We’ll create an app showing different ways to explore colors, specifically, motion create ColorViewer.

First we make the ./app/controllers directory (mkdir ./app/controllers). This is where we’ll keep all of our controller classes. ...

Get RubyMotion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.