我正在尝试导航到一个名为 HomePageView 的新 SwiftUI 文件(当前仅包含红色背景和显示主页的文本。)下面的代码我尝试与我的 Button 集成,这是我最初的 3 个按钮中的 1 个视图是 ContentView。没有错误,但是当我运行我的登录按钮时,它显示“登录已点击!” 文本,但不会将我带到 HomePageView。我是否错误地使用 NavigationLink?我知道我将遇到的下一个问题是一个页面上有多个按钮导致不同的目的地,有什么简单的方法可以解决这个问题,我正在尝试标记方法?
注意:一些视图文本中还有其他代码,它们只是图像和文本字段,以及另外两个按钮
@State private var current: Int? = nil
var body: some View {
NavigationLink(destination: HomePageView(), tag: 1, selection: self.$current) {
EmptyView()
}
Button(action: {
self.current = 1
print("Login tapped!")
}) {
Text("Login")
.fontWeight(.bold)
.foregroundColor(.orange)
.frame(width: deviceSize.size.width*(275/375), height: deviceSize.size.height*(45/812))
.cornerRadius(50)
.overlay(
Capsule(style: .continuous)
.stroke(Color.orange, style: StrokeStyle(lineWidth: 2)))
.frame(width: deviceSize.size.width, alignment: .center)
}.offset(y: deviceSize.size.height*(560/812))
}