I have a trouble trying to put my Picker inside NavigationLink child struct.
MyProblem
As you see after some transition (Main Page -> Testing Page -> Picker) and choosing any pickers desire option it navigate me back to Testing Page, but Picker itself stay grey. I know that it can be solved by adding NavigationView{}
inside NavigationLink child, but it causes another problem, because i already have NavigationView{}
in the top-level ancestor.
AnotherProblem_1
AnotherProblem_2
Code:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List{
NavigationLink(destination: page2()) {
Text("Food input")
}
NavigationLink(destination: page3()) {
Text("Тesting page")
}
}
.navigationBarTitle("Main page")
}
}
}
struct page3: View {
@State private var selectedFlavor = Flavor.chocolate
enum Flavor: String, CaseIterable, Identifiable {
case chocolate
case vanilla
case strawberry
var id: String { self.rawValue }
}
var body: some View {
NavigationView {
Form {
Section {
Picker("Flavor", selection: $selectedFlavor) {
Text("Chocolate").tag(Flavor.chocolate)
Text("Vanilla").tag(Flavor.vanilla)
Text("Strawberry").tag(Flavor.strawberry)
}
Text("Selected flavor: \(selectedFlavor.rawValue)")
}
}
}
}
}
UPDATE: Find out that my console is trying to tell me: "Returning an empty, disconnected UIBarButtonItem to fulfill the non-null contract" I don't know what that exactly mean, but i found strange solution:
.navigationViewStyle(StackNavigationViewStyle())
Apple documentation doesn't say anything about it, but if you set it up like this:
struct ContentView: View {
var body: some View {
NavigationView {
List{
NavigationLink(destination: page2()) {
Text("Food input")
}
NavigationLink(destination: page3()) {
Text("Тesting page")
}
}
.navigationBarTitle("Main page")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
All problem will gone. Please explain me how it works, i really stuck in that.
struct ContentView: View {
var body: some View {
NavigationView {
List{
NavigationLink(destination: page2()) {
Text("Food input")
}
NavigationLink(destination: page3()) {
Text("Тesting page")
}
}
.navigationBarTitle("Main page")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}