I'm trying to build a TabbedView
with the following simple code:
TabbedView {
Text("Hello world")
.tabItemLabel(Text("Hello"))
Text("Foo bar")
.tabItemLabel(Text("Foo"))
}
When running, both tabs are visible and enabled but the second tab's ("Foo") content is blank.
I was able to fix this by adding a
selection
state variable and passing that in for the selection:Now, tapping "Tab 2" will show "Tab 2!" on the screen, as opposed to a blank screen.
This was using Xcode 11.0 beta 2 (11M337n), macOS Catalina 10.15 Beta (19A487l).
In the newest version you should use
TabView
://Try this way, but you can't use an icon from SF Symbols, use the icons from //icons8.com struct ContentView: View {
var body: some View{
TabbedView { Living_R()
//Try this way, but you can't use an icon from SF Symbols, use the icons from //icons8.com or from another platform. or watch this tutorial https://www.youtube.com/watch?v=3PfCU5h5z94
Try adding tags:
In Xcode GM, TabbedView was renamed to TabView. So here's the right way to create a tab bar in SwiftUI now: