การเปิดหน้าจอด้วย NavigationLink
นำทางไปยัง View รายละเอียดเมื่อแตะ
การเปิดหน้าจอด้วย NavigationLink เป็นบทเรียน SwiftUI Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน SwiftUI Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Screens That Stack
Real apps move between screens. In SwiftUI you wrap your content in a NavigationStack so you can push new screens on top and slide back. 📱
NavigationStack {
HomeView()
}What NavigationLink Does
A NavigationLink is a tappable label that pushes a new view onto the stack. Tap it and the next screen slides in from the right.
NavigationLink("Details") {
DetailView()
}Link Lives Inside the Stack
A NavigationLink only works when it sits inside a NavigationStack. Without that wrapper, the tap has nowhere to push to and nothing happens.
NavigationStack {
NavigationLink("Open") { DetailView() }
}A Custom Label
The link label can be any view, not just text. Give the label closure a row of icon and text to make the tap target feel rich.
NavigationLink {
DetailView()
} label: {
Label("Profile", systemImage: "person")
}The Destination Closure
The first closure is the destination: the screen that appears when tapped. SwiftUI builds it lazily, only when the user actually navigates.
NavigationLink {
SettingsView()
} label: {
Text("Settings")
}The Back Button Is Free
You never build the back button yourself. The stack adds a back button automatically, and swiping from the left edge also returns to the previous screen. 👍
Links Inside Lists
Links shine in a List. Each row becomes tappable and gets a chevron, giving you the classic iOS drill-down feel for free.
List {
NavigationLink("Inbox") { InboxView() }
NavigationLink("Sent") { SentView() }
}Push, Do Not Replace
Pushing adds a screen on top of the stack rather than replacing the current one. That is why the back button can return you exactly where you were.
Nesting Goes Deep
A pushed screen can hold its own links, so users can drill down level after level. The stack remembers the whole path and unwinds it one tap at a time.
Keep One Stack Per Flow
Put a single NavigationStack at the root of each navigation flow. Nesting stacks inside each other usually causes confusing, broken back behavior.
A Tiny Mistake to Avoid
Forgetting the surrounding NavigationStack is the most common beginner bug. The link renders but tapping it does nothing, so always check the wrapper first.
Quick Check
Where must a NavigationLink live to actually push a screen?
Recap: Pushing Screens
You wrap content in a NavigationStack and use NavigationLink to push detail screens, with the back button handled for you. Next, you will pass data along. 🎉
คำถามที่พบบ่อย
บทเรียน “การเปิดหน้าจอด้วย NavigationLink” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การเปิดหน้าจอด้วย NavigationLink” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส SwiftUI Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การเปิดหน้าจอด้วย NavigationLink”
นำทางไปยัง View รายละเอียดเมื่อแตะ คุณปฏิบัติ SwiftUI Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน SwiftUI Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน SwiftUI Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “การเปิดหน้าจอด้วย NavigationLink” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน SwiftUI Academy นี้ได้ไหม
ได้ บทเรียน SwiftUI Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การเปิดหน้าจอด้วย NavigationLink
- การส่งข้อมูลไปยัง View รายละเอียด
- แถบเครื่องมือและชื่อการนำทาง
- เส้นทางการนำทางโดยใช้โค้ด