[英]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.