Chapter 14. Modal Dialogs

A modal dialog demands attention; while it is present, the user can do nothing other than work within it or dismiss it. This chapter discusses various forms of modal dialog:

  • Within your app, you can show alerts and action sheets. An alert is basically a message, possibly with an opportunity for text entry, and some buttons. An action sheet is effectively a column of buttons.

  • You can provide a sort of action sheet even when your app is not frontmost (or even running) by allowing the user to summon quick actions — also known as shortcut items — by long pressing on your app’s icon.

  • A local notification is an alert that the system presents on your app’s behalf, even when your app isn’t frontmost.

  • An activity view is typically summoned by the user from a Share button. It displays possible courses of external and internal action (activities), such as handing off data to another app, or processing data within your app. Your app can also provide activities that other apps can display in their activity views, through an action extension or share extension.

Alerts and Action Sheets

Alerts and action sheets are both forms of presented view controller (Chapter 6). They are managed through the UIAlertController class, a UIViewController subclass. To show an alert or an action sheet is a three-step process:

  1. Instantiate UIAlertController with init(title:message:preferredStyle:). The title: and message: are large and small descriptive text to appear at the ...

Get Programming iOS 14 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.