SwiftUIでNavigationViewの戻るボタンを非表示にする
SwiftUIでNavigationViewの戻るボタンを非表示にする方法です。
navigationBarBackButtonHidden
を false にすることで非表示にすることができます。

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
let fruits = ["Apple", "Banana", "Orange", "Grape", "Cherry", "Peach"] | |
var body: some View { | |
NavigationView { | |
List(fruits, id: \.self) { fruit in | |
NavigationLink(destination: SecondView(fruit: fruit)) { | |
Text(fruit) | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct SecondView: View { | |
let fruit: String | |
var body: some View { | |
Text(fruit) | |
.navigationBarBackButtonHidden(true) | |
} | |
} |