SwiftUI PresentationButton 无法构建 - 调用中参数 #1 缺少参数

SwiftUI PresentationButton fails to build - Missing argument for parameter #1 in call

我正在尝试在 SwiftUI 中实现 PresentationButton。我不断收到以下错误:

Missing argument for parameter #1 in call Insert '<#Label#>, '

我正在使用 Xcode 版本 11.0 beta。

这是我的 SwiftUI 文件:

import SwiftUI

struct HomeList : View {
    var body: some View {
        ScrollView(showsHorizontalIndicator: false) {
            HStack {
                ForEach(0 ..< 5/) { item in
                    PresentationButton(destination: ContentView()) {
                        CourseView()
                    }
                }
            }
        }
    }
}

#if DEBUG
struct HomeList_Previews : PreviewProvider {
    static var previews: some View {
        HomeList()
    }
}
#endif

struct CourseView : View {
    var body: some View {
        return VStack(alignment: .leading) {
            Text("Build an app with Swift UI")
                .font(.title)
                .fontWeight(.bold)
                .color(Color.white)
                .padding(20)
                .lineLimit(4)
                .frame(width: 120)

            Spacer()

            Image("Illustration1")
            }
            .background(Color("background3"))
            .cornerRadius(30)
            .frame(width: 246, height: 360)
            .shadow(color: Color("backgroundShadow3"), radius: 20, x: 0, y: 20)
    }
}

如@kontiki 所述,PresentationButton 已被弃用且不再可用。

您可以使用的替代品是 NavigationLink。这应该像 PresentationButton 一样工作。您还需要将 showsHorizontalIndicator: false 更改为 .horizontal, showsIndicators: false)

同时去掉你ForEach(0 ..< 5/)中的/。这可能是您出错的另一个原因。

struct HomeList : View {
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack {
                ForEach(0 ..< 5) { item in
                    NavigationLink(destination: ContentView()) {
                        CourseView()
                    }
                }
            }
        }
    }
}

如果您进行了这些更改,您应该不会出错。祝课程顺利:https://designcode.io/swiftui-course,我很喜欢。我不是想插入它,只是可以看到他正在学习该教程。

在我将 NavigationView 与 NavigationLink 结合使用后,它确实起作用了

这对我有用