简体   繁体   English

NavigationLink 无法正确加载我的个人视图 (SwiftUI)

[英]NavigationLink don't load my personal View correctly (SwiftUI)

I create a CardButton View and I use this in the ContentView:我创建了一个 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()
    }
}

When I added the Navigation Link, the image declared in the CardButton constructor is no longer displayed, and appears a blue circle in its place.当我添加导航链接时,在 CardButton 构造函数中声明的图像不再显示,并在其位置出现一个蓝色圆圈。

What I wrong?我错了什么?

The code of CardButton View: 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.

相关问题 我无法通过 SwiftUI 中的 NavigationLink 将我的 object 传递到另一个视图 - I cannot pass my object to another view with NavigationLink in SwiftUI SwiftUI 上的 NavigationLink 两次推送视图 - NavigationLink on SwiftUI pushes view twice SwiftUI 工具栏未显示在 NavigationLink 视图上 - SwiftUI toolbar not showing on a NavigationLink view 第一次加载View Controller时,UIButton不能正确对齐 - UIButtons don't align correctly upon first load of View Controller SwiftUI 从模态视图使用 NavigationLink 推送视图 - SwiftUI Push View with NavigationLink from modal view 强制一个 NavigationLink 到 SwiftUI 中的详细视图 - Force one NavigationLink to the detail view in SwiftUI 如何在没有 NavigationLink 的情况下导航到 SwiftUI 中的视图 - How to navigate to a View in SwiftUI without NavigationLink 我正在使用 NavigationLink 在视图之间导航,但它在 SwiftUI 的单个视图中不起作用 - I am using NavigationLink to navigate between views and it doesn't work in a single view in SwiftUI 为什么我不能以模态方式将结构发送到下一个视图,但可以通过 Navigationlink (SwiftUI) 正常工作 - Why can't I send a struct to the next view modally but works well through Navigationlink (SwiftUI) 无法单击列表(SwiftUI)中的NavigationLink - Can't click a NavigationLink in List (SwiftUI)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM