0

我正在尝试通过按钮操作将动态详细信息从母版页传递到详细信息页。我正在传递的视图,我正在使用动画从屏幕外动画到视图。当我传递简单的硬编码数据时,我能够让它工作,但是我在试图弄清楚如何让它传递特定于被点击的项目行的数据时遇到了问题。

我已经用按钮包装了项目行元素,但不确定我是否将正确的信息传递给按钮操作参数。

import SwiftUI

struct SearchView: View {
@State var show = false
var course = courseData
var body: some View {

    ZStack {

        ScrollView (.vertical, showsIndicators: false) {

            VStack(spacing: 0.0) {
                ForEach(course) { item in
                    Button(action: { self.show.toggle() })  {
                        CourseResultTile(perks: item.perks, hotdeals: item.hotdeals, image: item.image, courseName: item.courseName, distance: item.distance, reviews: item.reviews, priceSpan: item.priceSpan, timeSpan: item.timeSpan)
                    }
                }
            }
        }.offset(y: 120)

// 在下面查看我正在制作动画 //

        FacilityView(show: $show, perks: self.perks, image: self.image, courseName: self.courseName, address: self.address)
            .rotation3DEffect(Angle(degrees: show ? 0 : 60), axis: (x: 0, y: 10.0, z: 0))
            .animation(.default)
            .offset(x: show ? 0 : -UIScreen.main.bounds.width)
            .onTapGesture {
                self.show.toggle()
        }

    }
    .navigationBarTitle(Text("Search"), displayMode: .inline)
    .navigationBarHidden(true)
    .edgesIgnoringSafeArea(.top)



}
}

// 课程数据模型 //

struct Course : Identifiable {
var id = UUID()
var hotdeals: String
var perks: String
var image: String
var courseName: String
var distance: String
var reviews: String
var priceSpan: String
var timeSpan: String
var address: String
}

let courseData = [
Course(hotdeals: "Badge_HotDeals", perks: "Badge_NoPerks", image: "Image_CourseBackground", courseName: "Timacuan Golf Club", distance: "16.8 miles", reviews: "(562)", priceSpan: "$12.00 - $34.00", timeSpan: "1:53PM - 6:00 PM", address: "550 Timacuan Boulevard, Lake Mary, Florida, 32746"),
Course(hotdeals: "Badge_HotDeals", perks: "Badge_NoPerks", image: "Image_Course1", courseName: "Sanctuary Ridge Golf Club", distance: "20.1 miles", reviews: "(895)", priceSpan: "$12.00 - $34.95", timeSpan: "8:46 AM - 5:02 PM", address: "2601 Diamond Club Drive, Clermont, Florida, 34711"),
Course(hotdeals: "Badge_HotDeals", perks: "Badge_NoPerks", image: "Image_Course2", courseName: "Eagle Creek Golf Club - FL", distance: "14.3 miles", reviews: "(1K)", priceSpan: "$12.00 - $42.00", timeSpan: "8:42 AM - 5:51 PM", address: "10350 Emerson Lake Blvd, Orlando, Florida, 32832")

// FacilityView 摘录 //

import SwiftUI

struct FacilityView: View {

var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateStyle = .medium
return formatter
}


var perks = "Badge_NoPerks"
var image = "Image_Course6"
var courseName = "Panther Lake: Orange County National"
var address = "16301 Phil Ritson Way, Winter Garden, FL 34787"
var holes = "18"
var par = "72"
var length = "6836"
var slope = "127"

@Binding var show: Bool
@State private var todaysDate = Date()

我得到的错误是“‘SearchView’类型的值没有成员‘我试图传递的变量’

4

0 回答 0