I'm having an issue playing around with the TabbedView that doesn't seem to load the content when I switch between tabs in the Simulator.
If I have the app start on Tab 1, using something like:
TabbedView(selection: .constant(1))
...the content within the view of the first tab displays perfectly. But after clicking on Tab 2 manually, the content in Tab 2's view doesn't display. However, if I have the app start with Tab 2, the content in Tab 2 displays fine...but the content of Tab 1 doesn't display when I click on it. It's almost as if it isn't refreshing the view in a TabbedView situation as I attempt to switch between them, but each loads properly when it is designated as the TabbedView's starting position only.
If I don't designate starting position, the app defaults to Tab 1 as the starting point and the issue remains the same as if I had designated the starting point manually.
With SwiftUI being so new, I'm probably just missing something very simple...
Any ideas? Thanks everyone!
Dump of "ContentView.Swift"
import SwiftUI
struct ContentView : View {
var body: some View {
TabbedView {
SettingsView()
.tabItemLabel(Text("Settings"))
HistoryView()
.tabItemLabel(Text("History"))
}
Dump of "SettingsView.swift"
import SwiftUI
struct SettingsView : View {
var body: some View {
Text("Settings View, First Tab Location")
}
}
Dump of "HistoryView.swift"
import SwiftUI
struct HistoryView : View {
var body: some View {
Text("History View, 2nd Lab Location")
}
}
Doh, it looks like I figured it out...
I've resolved this by simply adding: tag(1) and tag(2) to each tabItemLabel
(See below)
import SwiftUI
struct ContentView : View {
var body: some View {
TabbedView {
SettingsView()
.tabItemLabel(Text("Settings")).tag(1)
HistoryView()
.tabItemLabel(Text("History")).tag(2)
}