[英]Views content not showing on switching to other tabs using TabbedView of SwiftUI
I'm implementing TabbedView
using SwiftUI
framework by referring https://developer.apple.com/documentation/swiftui/tabview我正在通过参考https://developer.apple.com/documentation/swiftui/tabview使用
SwiftUI
框架实现TabbedView
When running on the simulator, only the first tab view contents showing and other tabs contents not showing.在模拟器上运行时,只显示第一个选项卡视图内容,不显示其他选项卡内容。 Even after restarting XCode, simulator etc.
即使在重新启动 XCode、模拟器等之后。
App video link: https://youtu.be/Gibu8jfQQ5I应用视频链接: https : //youtu.be/Gibu8jfQQ5I
struct ContentView : View {
var body: some View {
TabbedView {
Text("The First Tab")
.tabItem {
Image(systemName: "1.square.fill")
Text("First")
}
Text("Another Tab")
.tabItem {
Image(systemName: "2.square.fill")
Text("Second")
}
Text("The Last Tab")
.tabItem {
Image(systemName: "3.square.fill")
Text("Third")
}
}.font(.headline)
}
}
Appreciate you help and suggestions!感谢您的帮助和建议!
In beta 5, your code works, and also TabbedView
was renamed to TabView
.在 beta 5 中,您的代码有效,并且
TabbedView
也被重命名为TabView
。 If you cannot upgrade to beta 5 yet, to fix your problem in beta 4, you need to add .tag(n)
to each view:如果您还不能升级到 beta 5,要解决 beta 4 中的问题,您需要将
.tag(n)
添加到每个视图:
struct ContentView : View {
var body: some View {
TabbedView {
Text("The First Tab").tag(1)
.tabItem {
Image(systemName: "1.square.fill")
Text("First")
}
Text("Another Tab").tag(2)
.tabItem {
Image(systemName: "2.square.fill")
Text("Second")
}
Text("The Last Tab").tag(3)
.tabItem {
Image(systemName: "3.square.fill")
Text("Third")
}
}.font(.headline)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.