0Pricing
SwiftUI Academy · Pelajaran

Membuka Layar dengan NavigationLink

Buka view detail saat diketuk.

Membuka Layar dengan NavigationLink adalah pelajaran SwiftUI Academy gratis di CoddyKit. Ini adalah pelajaran 1 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar SwiftUI Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus SwiftUI Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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. 🎉

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Membuka Layar dengan NavigationLink” gratis?

Ya — teks lengkap “Membuka Layar dengan NavigationLink” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus SwiftUI Academy, upgrade ke CoddyKit PRO. Kursus SwiftUI Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Membuka Layar dengan NavigationLink”?

Buka view detail saat diketuk. Kamu berlatih SwiftUI Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai SwiftUI Academy?

Tidak diperlukan pengalaman sebelumnya. SwiftUI Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 4.

Berapa lama pelajaran “Membuka Layar dengan NavigationLink” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran SwiftUI Academy ini?

Ya. Setiap pelajaran SwiftUI Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Membuka Layar dengan NavigationLink
  2. Meneruskan Data ke View Detail
  3. Bilah Alat dan Judul Navigasi
  4. Jalur Navigasi Terprogram
← Kembali ke SwiftUI Academy