Okna dialogowe potwierdzenia
Oferuj destrukcyjne opcje za pomocą confirmationDialog
Okna dialogowe potwierdzenia to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej SwiftUI Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
What Is a Confirmation Dialog?
A confirmation dialog is an action sheet that slides up with a list of choices, perfect for offering several options at once. 🗂️
Dialog vs Alert
An alert centers on screen for one key decision. A dialog rises from the bottom and suits a menu of related actions instead.
Triggered by a Boolean
Like sheets and alerts, a dialog opens when a boolean state turns true. Store the flag and flip it from a button tap.
@State private var showDialog = falseThe confirmationDialog Modifier
Attach confirmationDialog to a view with a title and a boolean binding. SwiftUI presents the choices when the flag is true.
.confirmationDialog("Choose", isPresented: $showDialog) {
Button("Photo Library") { }
}Listing Choices as Buttons
Each option is a button inside the dialog. SwiftUI stacks them and runs the action of whichever one the user taps.
Button("Camera") { }
Button("Photo Library") { }A Destructive Option
Use the .destructive role for risky choices like delete. The button turns red so users notice before committing.
Button("Delete Account", role: .destructive) { }The Cancel Button
SwiftUI adds a Cancel button automatically. You can also supply your own with role .cancel to control its wording.
Button("Not now", role: .cancel) { }Adding a Title Message
Pass a message closure to explain the choice. It shows as a short caption above the buttons to guide the decision.
.confirmationDialog("Remove item?", isPresented: $show) {
Button("Remove", role: .destructive) { }
} message: {
Text("You can add it again later.")
}Reacting to a Choice
Each button's action runs on tap, then the dialog closes. Put the matching logic, like pick or delete, inside that closure.
Button("Save") { saveDocument() }Dialogs Adapt by Device
On iPhone a dialog rises as an action sheet. On iPad and Mac it appears as a popover near the control that opened it.
When to Use a Dialog
Reach for a dialog when a single tap could mean several things, like sharing or choosing an image source. It keeps options tidy.
Quick Check
When is a confirmation dialog the better choice over an alert?
Recap: Dialogs
You can now present a confirmation dialog from a boolean, list action buttons, and mark destructive choices in red. You finished the course! 🎉
Często zadawane pytania
Czy lekcja „Okna dialogowe potwierdzenia” jest bezpłatna?
Tak — pełny tekst „Okna dialogowe potwierdzenia” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu SwiftUI Academy, przejdź na CoddyKit PRO. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Okna dialogowe potwierdzenia”?
Oferuj destrukcyjne opcje za pomocą confirmationDialog Ćwiczysz SwiftUI Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć SwiftUI Academy?
Nie wymagamy żadnego doświadczenia. SwiftUI Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Okna dialogowe potwierdzenia”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji SwiftUI Academy?
Tak. Każda lekcja SwiftUI Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Prezentowanie arkusza
- Detenty i wskaźniki przeciągania
- Alerty z akcjami
- Okna dialogowe potwierdzenia