【问题标题】:SwiftUI PresentationButton fails to build - Missing argument for parameter #1 in callSwiftUI PresentationButton 无法构建 - 调用中的参数 #1 缺少参数
【发布时间】:2019-12-08 13:55:38
【问题描述】:

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

调用中的参数 #1 缺少参数 插入 ', '

我使用的是 Xcode 11.0 测试版。

这是我的 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)
    }
}

【问题讨论】:

  • 您使用的是 beta 1?如果您想在这里获得帮助,您可能应该升级到最新版本(beta 5)。 很多已经改变。这一次,PresentationButton 已被弃用,不再可用。

标签: swift swiftui


【解决方案1】:

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

swiftUI PresentaionLink does not work second time

这对我有用

【讨论】:

    【解决方案2】:

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

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

    同时取出ForEach(0 ..&lt; 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,我很喜欢。我不是想插上它,只是可以看出他正在按照该教程进行操作。

    【讨论】:

    • 这在 beta6 中不起作用。在我将 NavigationView 与 NavigationLink 结合使用后,它确实起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    相关资源
    最近更新 更多