How to Use the NavigationButton with SwiftUI?
We will give the columns in our List structure that we created with SwiftUI the action of switching to other pages. We need to use the NavigationButton for this operation.
The performance Segue operations we perform with UIKit have been simplified in the SwiftUI structure. In this way, the process of switching between pages is very easy.
On the example below, you can see the use of the ForEach structure with List.
import SwiftUI
import PlaygroundSupport
struct XView:View {
var body: some View {
Text("😛")
}
}
struct CustomView:View {
var body: some View {
NavigationView {
List {
ForEach(["A", "B", "C"].identified(by: \.self)) { row in
NavigationButton(destination: XView()) {
Text(row)
}
}
}
}
}
}
PlaygroundPage.current.liveView = UIHostingController(rootView: CustomView())
Post Comment