我正在尝试从一个视图移动到另一个视图,我已使用NavigationLink如下:
@State private var isActive = false
NavigationLink(destination: DetailsView(),
isActive: $isActive) {
Text("")}
Button(action: {
print ("Clicked")
self.isActive = true
}){
Text("More Details")
.font(.headline)
.bold()
.padding(.all, 10)
.padding(.leading, 10)
.padding(.trailing, 10)
.foregroundColor(.white)
.background(Color.orange.frame(width: 300, height: 50) .clipShape(RoundedRectangle(cornerRadius: 20)))
}
不幸的是没有用!!该按钮没有带我进入详细信息视图!我已经检查了这里的大多数解决方案,但是对我没有用:(请帮助!
要使用NavigationLink
,必须将其包装在NavigationView
中
struct ContentView: View {
var body: some View {
NavigationView { // <--- add this
NavigationLink(destination: DetailsView()) {
Text("ADD TO CART")
.font(.headline)
.bold()
.padding(.all, 10)
.padding(.leading, 10)
.padding(.trailing, 10)
.foregroundColor(.white)
.background(Color.orange.frame(width: 300, height: 50) .clipShape(RoundedRectangle(cornerRadius: 20)))
}
}
}
}