การแสดงชีต
แสดงมุมมองโมดัลด้วยชีตและการเชื่อมโยงข้อมูล
การแสดงชีต เป็นบทเรียน SwiftUI Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน SwiftUI Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What Is a Sheet?
A sheet is a card that slides up from the bottom to show extra content, like a form or detail, without leaving your current screen. 📄
Sheets Need a Trigger
A sheet appears when a boolean state flips to true. You store that flag in your view and flip it when the user taps something.
@State private var showSheet = falseThe .sheet Modifier
You attach .sheet to a view and bind it to your boolean. When the value is true, SwiftUI presents the content you return.
.sheet(isPresented: $showSheet) {
Text("Hello from the sheet!")
}The Dollar Sign Binding
The $ before showSheet passes a two-way binding, so SwiftUI can both read the flag and reset it to false when the sheet closes.
.sheet(isPresented: $showSheet) { DetailView() }Opening the Sheet
Set the boolean to true from a button action and the sheet animates up automatically. You never call a present function yourself. ✨
Button("Show Details") {
showSheet = true
}Putting It Together
Combine the button, the state, and the .sheet modifier on one view and you have a working modal in just a few lines.
Button("Open") { showSheet = true }
.sheet(isPresented: $showSheet) {
Text("Sheet content")
}Dismissing a Sheet
Users can swipe a sheet down to close it. To dismiss it in code, read the dismiss action from the environment inside the sheet.
@Environment(\.dismiss) private var dismissCalling dismiss()
Give the sheet a Done button that calls dismiss(). This is the polite way to let users finish and return to the main screen.
Button("Done") { dismiss() }Sheets Get Their Own State
A sheet is a normal SwiftUI view, so it can hold its own state, modifiers, and even another sheet. Treat it like any other screen.
Presenting With an Item
Use sheet(item:) when the sheet depends on a selected value. SwiftUI shows the sheet whenever that optional item is non-nil.
.sheet(item: $selectedBook) { book in
BookDetail(book: book)
}One Sheet at a Time
A view shows one sheet per modifier. For several modals, use separate flags or item bindings so they never collide on screen.
Quick Check
How do you tell SwiftUI to present a sheet?
Recap: Sheets
You learned that a sheet slides up from a boolean flag, attaches with .sheet, and closes via swipe or the dismiss action. Nice work! 🎉
คำถามที่พบบ่อย
บทเรียน “การแสดงชีต” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การแสดงชีต” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส SwiftUI Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การแสดงชีต”
แสดงมุมมองโมดัลด้วยชีตและการเชื่อมโยงข้อมูล คุณปฏิบัติ SwiftUI Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน SwiftUI Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน SwiftUI Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “การแสดงชีต” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน SwiftUI Academy นี้ได้ไหม
ได้ บทเรียน SwiftUI Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ