I am trying to do a basic TabbedView. The code below runs and when you tap each tab it updates to show the current selected page.
The problem is when I uncomment the Binding in AView. That triggers an error in ContentView:
$tabIndex is marked "ContentView.swift:14:31: Cannot convert value of type 'Binding<Int>' to expected argument type 'Binding<_>'"
Until I uncomment the Binding the TabbedView is perfectly happy to accept a Binding<Int> but once I want to use that binding problem!
Any ideas? Am I doing this all wrong?
struct ContentView : View {
@State var tabIndex: Int = 1
var body: some View {
TabbedView(selection: $tabIndex){
AView().tabItemLabel(
Text("Page A: \($tabIndex.value)")
).tag(0)
AView().tabItemLabel(
Text("Page B: \($tabIndex.value)")
).tag(1)
AView().tabItemLabel(
Text("Page C: \($tabIndex.value)")
).tag(2)
}
}
}
struct AView : View {
// @Binding private var tabIndex: Int
var body: some View {
Text("Hello World ")
}
}