我正在尝试集成NavigationStack到我的 SwiftUI 应用程序中。
我有四种看法:CealUIApp、OnBoardingView、UserTypeView。RegisterView
我想当用户按下 中的按钮时从 导航OnBoardingView到。UserTypeViewOnBoardingView
并且,当用户按下按钮时从 导航UserTypeView到RegisterViewUserTypeView
下面是我的 CealUIApp 代码
@main
struct CealUIApp: App {
@State private var path = [String]()
var body: some Scene {
WindowGroup {
NavigationStack(path: $path){
OnBoardingView(path: $path)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在OnBoardingView
Button {
path.append("UserTypeView")
}
label: {
Text("Hello")
}
.navigationDestination(for: String.self) { string in
UserTypeView(path: $path)
}
Run Code Online (Sandbox Code Playgroud)
在UserTypeView
Button {
path.append("RegisterView")
}
label: …Run Code Online (Sandbox Code Playgroud) 我用我@EnvironmentObject的让我的 TeamData 可以被不同的人使用,但它不能很好地工作。当我通过列表中的导航链接转到另一个视图时,这很好。当我点击同一个视图的按钮时,它崩溃了..
我想我放错了什么。有人可以帮助解决这个问题吗?这是否意味着我需要先@EnvironmentObject在 NavigationView添加才能使用它?谢谢
演示:https : //youtu.be/-iRadrHd94c
import SwiftUI
struct GameRecordListView: View {
@EnvironmentObject var teamResult : TeamResult
@State var hint : String = ""
@State var successRegistration : Bool = false
@State var sheetPresented: Bool = false
var body: some View {
VStack{
List(0 ..< 12){ item in
NavigationLink(destination: GameDetailRecordView()){ <-this works well
Text("444")
}
}
VStack{
Spacer()
HStack{
Spacer()
NavigationLink(destination: GameDetailRecordView()) <-this doesn't works well and crashed
{
Image(systemName: "pencil.circle")
.resizable()
.frame(width: …Run Code Online (Sandbox Code Playgroud)