UIAlertController
for an alert view or an action sheet

I retrofitted an alert view and an action sheet into the Still project.

This is the alert view (of style UIAlertControllerStyle.Alert) that would have been displayed if there was no source from which to pick an image. An alert view displays a message. When the user presses OK, it disappears.

This is the action sheet (of style UIAlertControllerStyle.ActionSheet) that is displayed when there are sources from which to pick an image. An action sheet asks the user to make a choice, and then it disappears.

Source code in Still.zip

  1. AppDelegate.swift: unchanged.
  2. ViewController.swift
  3. View.swift
  4. Info.plist

The UIAlertController

The UIAlertController’s view is displayed modally (temporarily) by calling the first view controller’s method presentViewController(_:animated:completion:), which we saw in Modal. This method cannot be called in the first view controller’s init, loadView, or viewDidLoad methods (but it can be called in viewDidAppear). It can only be called after the first view controller’s view is displayed in the window.