' 关闭结果类型 '_',ios,swift,xcode,swiftui"/>

首页 > 解决方案 > 无法转换“NavigationLink”类型的值' 关闭结果类型 '_'

问题描述

我收到以下错误:

无法将“NavigationLink”类型的值转换为闭包结果类型“_”

你知道这里有什么问题吗?

我的内容视图文件:

@ObservedObject var voucherData = VoucherData()

    var body: some View {
        NavigationView {
            ZStack {
                List {
                    ForEach(voucherData.voucherList) { voucher in
                        NavigationLink(destination: EditView(value:voucher.value, currency: voucher.currency, shopName: voucher.shopName)) {
                            VStack() {

在另一个文件中:

struct Voucher : Identifiable {
    let id = UUID()
    var value : String = ""
    var currency : String = ""
    var shopName : String = ""
}

final class VoucherData: ObservableObject {
    @Published var voucherList: [Voucher] = [
        .init(value: "100", currency: "USD", shopName: "FlyBurger")]
}

标签: iosswiftxcodeswiftui

解决方案


我假设您的 EditView 只是缺少参数凭证:

struct EditView: View {

    let voucher: Voucher

    ...
}

现在您可以像这样传递凭证:

NavigationLink(destination: EditView(voucher: voucher)) {

推荐阅读