簡體   English   中英

NavigationLink 無法正確加載我的個人視圖 (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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM