swiftui - SwiftUI - 如何使用 TabView 弹出到根目录?
问题描述
在 NavigationView 中使用 TabView 时,我无法弹出到根目录工作。交换这些顺序不符合我的应用程序的设计。
我已按照 此答案中的解决方案进行操作,但无济于事:
struct ContentView: View {
@State var selection = 0
var body: some View {
NavigationView {
TabView(selection: $selection) {
FirstTabView()
.tabItem {
Label("Home", systemImage: "house")
}
.tag(0)
}
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
struct FirstTabView: View {
@State var isActive = false
var body: some View {
NavigationLink("SecondView Link", destination: SecondView(secondViewIsActive: $isActive), isActive: $isActive)
.isDetailLink(false)
}
}
struct SecondView: View {
@Binding var secondViewIsActive: Bool
var body: some View {
NavigationLink("ThirdView Link", destination: ThirdView(thirdViewIsActive: $secondViewIsActive))
}
}
struct ThirdView: View {
@Binding var thirdViewIsActive: Bool
var body: some View {
Text("Third View")
Button("Pop To Root") {
thirdViewIsActive = false
}
}
}
调试控制台显示此错误:
Trying to pop to a missing destination at /Library/Caches/com.apple.xbs/Sources/Monoceros_Sim/Monoceros-120/Shared/NavigationBridge_PhoneTV.swift:341
如果我注释掉上面与 TabView 相关的行,则 pop to root 有效。
解决方案
推荐阅读
- angular - Angular 2.0.0 的文本编辑器
- flutter - 有没有办法让firebase实时数据库存在系统更快地检测到断开连接?
- bash - 如何在 Linux 的命令中插入单词?
- python - Python正在输出带有字符串引号的json
- excel - 图像控制用户窗体替代
- ios - 列表未在 SwiftUI 中显示来自 API 的数据?
- amazon-web-services - 命名 AWS EC2 安全组
- python-2.7 - 在python2.7中导入jwcrypto时出错
- c# - 使用 ClosedXML.Excel C# 更改列样式
- python - 命令引发异常:AttributeError: 'File' object has no attribute 'to_dict' for Discord bot