[英]I cannot pass my object to another view with NavigationLink in SwiftUI
[英]NavigationLink don't load my personal View correctly (SwiftUI)
我创建了一个 CardButton 视图,并在 ContentView 中使用它:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
Form{
VStack(alignment: .leading){
ScrollView(.vertical, showsIndicators: true){
VStack(alignment: .leading){
NavigationLink(destination: NewScore(), label: {
CardButton(textCard: "Text1", image: "image1")
})
NavigationLink(destination: ScoreSaved(), label: {
CardButton(textCard: "Text2",image: "image2")
})
NavigationLink(destination: Analisys(), label: {
CardButton(textCard: "Text13",image: "image3")
})
}
}
}
}
.navigationBarTitle(Text("Title1"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
当我添加导航链接时,在 CardButton 构造函数中声明的图像不再显示,并在其位置出现一个蓝色圆圈。
我错了什么?
CardButton 视图的代码:
import SwiftUI
struct CardButton: View {
var textCard: String
var image: String
init(textCard: String, image: String){
self.textCard = textCard
self.image = image
}
var body: some View {
VStack {
HStack{
Image(image)
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(Circle())
.shadow(radius: 20)
.frame(width:190,height: 190)
Text(textCard)
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color.orange)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.