我想从一个屏幕导航到另一个屏幕。因此,我使用了NavigationLink。每当我单击按钮时,什么都不会发生,甚至在控制台中也没有打印语句。
代码如下:
struct _LoginView: View {
var body: some View {
Color.green
.edgesIgnoringSafeArea(.all)
.overlay(
VStack(alignment: .center, spacing: 15) {
Image("Bg")
.resizable()
.scaledToFill()
.frame(width: 130, height: 130, alignment: .center)
.clipShape(Circle())
Spacer()
NavigationLink(destination: _LoginViewMain()) {
Button(action: {
print("button clicked")
}) {
Text("SIGN IN")
.frame(minWidth: 0, maxWidth: .infinity)
.font(.system(size: 18))
.padding()
.foregroundColor(.white)
.overlay( RoundedRectangle(cornerRadius: 25)
.stroke(Color.white, lineWidth: 2)
)
}
}
NavigationLink(destination: _LoginViewMain()) {
Button(action: {
print("btn cliecked")
}) {
Text("SIGN UP")
.frame(minWidth: 0, maxWidth: .infinity)
.font(.system(size: 18))
.padding()
.foregroundColor(.green)
}
.background(Color.white)
.cornerRadius(25)
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.padding([.leading, .trailing], 30)
.foregroundColor(Color.green)
.padding([.top, .bottom], 100)
)
}
}
有人可以帮助我知道导航链接未触发的原因吗?
答案 0 :(得分:1)
您必须将NavigationLink嵌入到NavigationView中。请尝试下面的代码段。
BUCHK=789