Alert actions allow you to perform tasks when a particular button on an alert is clicked or tapped. The action includes both the text on the button and the code that should run when the button is pressed. See how alert actions work in this brief tutorial video.
- [Instructor] In order to add buttons to your alert,…you need to add something called a UIAlertAction.…A UIAlertAction has information about the button…including the text on the button…and what the button actually does when it's pressed.…It also includes information about the style of the button.…Is the button going to cancel an action?…Is the button going to perform an action?…Is the button going to delete something?…So, you have all of those choices when you create an action.…
Let's go right below where we create the alert…and we'll create a constant called action1…and set it equal to a UIAlertAction,…open up the parentheses.…I'll just use return to have Xcode write out…that constructor for me.…For the title, I'll put the string OK.…For the style, I'll type a dot and you can hit cancel,…default, or destructive.…These options do what you would expect.…Cancel is a style for buttons when you want…to cancel an action.…
The default is the standard button when you want…to perform some kind of an action…and destruction signifies to the user…
- Alert controllers and actions
- Sliders, progress bars, and switches
- Creating UI elements with code
- Displaying web content with Safari view controllers and WKWebView
- Creating collection view controllers
- Creating tabbed apps
- Publishing your app with App Store Connect
Skill Level Beginner
1. Master Views
2. Display Web Content
3. Collection Views
4. Multiview Templates
Customize a table view cell4m 18s
5. Publish an App
Next steps3m 28s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.