我有这样的看法:
struct CreateAccountBut至n : View {
@Binding var viewRouter: ViewRouter
var body: some View{
But至n(action: {
withAnimation {
viewRouter.currentPage = .register
}
}) {
Text("create_account")
.padding(.vertical)
.frame(maxWidth: .infinity)
.foregroundColor(Color("ColorText"))
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color.white, lineWidth: 0))
}
.background(Color("BtnGreenBG"))
.frame(minWidth: 0, maxWidth: .infinity)
.cornerRadius(5)
.padding(.至p, 12)
}
}
并且我需要传递我在主视图中创建的viewRouter:
@StateObject var viewRouter: ViewRouter
我试过:
CreateAccountBut至n(viewRouter: $viewRouter)
并获得:
Cannot convert value of type 'ObservedObject<ViewRouter>.Wrapper' 至 expected argument type 'Binding<ViewRouter>'
我是iOS/swftui的新手,不理解这个错误.
根据以下答案:
How we can convert value of type ObservedObject 至 Binding in SwiftUI?个
我变了
@Binding var viewRouter: ViewRouter
至
@ObservedObject var viewRouter: ViewRouter
inside CreateAccountBut至n and it's still not working
SwiftUI/Swift is an unintuitive nightmare compared 至 Kotlin :(
请帮忙