我试图从登录视图推到详细视图,但无法实现。即使在登录视图中也没有显示导航栏。如何在SwiftUI中进行按钮点击推送?如何在按钮点击时使用NavigationLink?
我想在SwiftUI中通过按钮点击推送从登录视图到详细视图,但是即使在登录视图中也没有显示导航栏。请问如何实现?如何在按钮点击时使用NavigationLink?
var body: some View {
NavigationView {
VStack(alignment: .leading) {
Text("Let's get you signed in.")
.bold()
.font(.system(size: 40))
.multilineTextAlignment(.leading)
.frame(width: 300, height: 100, alignment: .topLeading)
.padding(Edge.Set.bottom, 50)
Text("Email address:")
.font(.headline)
TextField("Email", text: $email)
.frame(height:44)
.accentColor(Color.white)
.background(Color(UIColor.darkGray))
.cornerRadius(4.0)
Text("Password:")
.font(.headline)
SecureField("Password", text: $password)
.frame(height:44)
.accentColor(Color.white)
.background(Color(UIColor.darkGray))
.cornerRadius(4.0)
Button(action: {
print("login tapped")
}) {
HStack {
Spacer()
Text("Login").foregroundColor(Color.white).bold()
Spacer()
}
}
.accentColor(Color.black)
.padding()
.background(Color(UIColor.darkGray))
.cornerRadius(4.0)
.padding(Edge.Set.vertical, 20)
}
.padding(.horizontal,30)
}
.navigationBarTitle(Text("Login"))
}
NavigationLink(destination:isActive:)
对于具有多个导航链接的视图不适用吗? - user482594NavigationLink(destination:isActive:)
- 由多个@State
变量控制。如果链接彼此独立,则此方法效果最佳。但是,当您需要添加多个相关的 NavigationLinks(例如在列表中等)时,NavigationLink(destination:tag:selection:)
可能更适合。 - pawello2222