使用 NavigationLink 将信息传递到另一个视图 [英] Pass information to another view with NavigationLink

查看:52
本文介绍了使用 NavigationLink 将信息传递到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下视图,我需要将 item 内容传递给另一个视图 (DetailsEvent.swift),我正在使用 NavigationLink .(我使用的是 Xcode 11 GM)

I have following View and I need to pass item content to another View (DetailsEvent.swift), I am using NavigationLink . (I'm using Xcode 11 GM)

struct Events: View {

    @ObservedObject var networkManager = NetworkManager()

    var body: some View {

        NavigationView{

            List(self.networkManager.eventos.events){ item in

                NavigationLink(destination: DetailsEvent(item: item))  {

                    VStack(alignment: .leading) {

                      HStack {

                        Image(systemName: "calendar")
                        .foregroundColor(.gray)

                        Text(item.start_date)
                            .font(.subheadline)
                            .foregroundColor(.gray)
                      }

                    Text(item.title)
                        .font(.headline)                    
                }
              }

           }
            .navigationBarTitle("Events")
        }
    }

但它给了我以下错误:

传递给不带参数的调用的参数

Argument passed to call that takes no arguments

不传递任何变量:NavigationLink (destination: DetailsEvent () 一切正常.

Without passing any variable: NavigationLink (destination: DetailsEvent () everything works fine.

DetailsEvent.swift

DetailsEvent.swift

struct DetailsEvent: View {
    var body: some View {
        Text("here details content")
    }
}

推荐答案

您的结构没有名为 item 的属性.你需要这样的东西:

Your struct has no property called item. You need something like this:

struct DetailsEvent: View {

    let item: Event

    var body: some View {
        Text("here details about \(item.title)")
    }
}

这篇关于使用 NavigationLink 将信息传递到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆