0Pricing
SwiftUI Academy · درس

مربعات حوار التأكيد

اعرض خيارات مدمّرة باستخدام confirmationDialog

مربعات حوار التأكيد درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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 = false

The 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! 🎉

الأسئلة الشائعة

هل درس «مربعات حوار التأكيد» مجاني؟

نعم — نص درس «مربعات حوار التأكيد» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «مربعات حوار التأكيد»؟

اعرض خيارات مدمّرة باستخدام confirmationDialog تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «مربعات حوار التأكيد»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. عرض ورقة
  2. محددات الارتفاع ومؤشرات السحب
  3. تنبيهات مع إجراءات
  4. مربعات حوار التأكيد
← العودة إلى SwiftUI Academy