Open aralez-g0lem opened 1 year ago
Use a @Binding var selection: Item
in Another View and pass it $selection
. This will allow you to update the state.
Reci
Use a
@Binding var selection: Item
in Another View and pass it$selection
. This will allow you to update the state.
Receiving error
Type 'Binding<Item>' has no member 'home'
that is just telling that you probably removed home from your enum or that it is taking some other Item
type instead of your enum (the naming is very generic).
It would be something like this:
struct GeneralView View {
@State private var selection: Item = .home
var body: some View {
ZStack {
TabBar(selection: $selection, visibility: $visibility) {
// ... some more code....
}
StickyHeaderView(selection: $selection)
}
}
// ... some more code....
struct StickyHeaderView: View {
@Binding var selection: Item
var body: some View {
Button("Selection to letters") {
selection = .letters
}
}
How I can updated selected State if I'm navigating to view (presented TabBar), but not from TabBar, like from button inside of another view, or using NavigationLink in another view.
Thank you
View with TabBar
Another View