我收到一个名为“传递给不带参数的调用的参数”的错误

ZOE*_*EIM 2 ios swift swiftui

我正在关注 Scrumdinger 应用程序的 ios 应用程序开发教程,并且我一直在遵循该教程,并且它一直有效,直到我完成“使用绑定传递数据”部分。我在第 58 行“DetailEditView(data: $data)”上不断出现错误。这正是教程所说的,所以我不知道为什么会出现错误。

这是我的详细视图文件的完整代码:“

//
//  DetailView.swift
//  Scrumdinger
//
//  Created by ZOE HEIM on 4/25/22.
//

import Foundation

import SwiftUI

struct DetailView: View {
    @Binding var scrum: DailyScrum
    
    @State private var data = DailyScrum.Data()
    @State private var isPresentingEditView = false
    
    var body: some View {
        List {
            Section(header: Text("Meeting Info")) {
                NavigationLink(destination: MeetingView()) {
                    Label("Start Meeting", systemImage: "timer")
                        .font(.headline)
                        .foregroundColor(.accentColor)
                }
                HStack {
                    Label("Length", systemImage: "clock")
                    Spacer()
                    Text("\(scrum.lengthInMinutes) minutes")
                }
                .accessibilityElement(children: .combine)
                HStack {
                    Label("Theme", systemImage: "paintpalette")
                    Spacer()
                    Text(scrum.theme.name)
                        .padding(4)
                        .foregroundColor(scrum.theme.accentColor)
                        .background(scrum.theme.mainColor)
                        .cornerRadius(4)
                }
                .accessibilityElement(children: .combine)
            }
            Section(header: Text("Attendees")) {
                ForEach(scrum.attendees) { attendee in
                    Label(attendee.name, systemImage: "person")
                }
            }
        }
        .navigationTitle(scrum.title)
        .toolbar {
            Button("Edit") {
                isPresentingEditView = true
                data = scrum.data
            }
        }
        .sheet(isPresented: $isPresentingEditView) {
            NavigationView {
                DetailEditView(data: $data)
                    .navigationTitle(scrum.title)
                    .toolbar {
                        ToolbarItem(placement: .cancellationAction) {
                            Button("Cancel") {
                                isPresentingEditView = false
                            }
                        }
                        ToolbarItem(placement: .confirmationAction) {
                            Button("Done") {
                                isPresentingEditView = false
                                scrum.update(from: data)
                            }
                        }
                    }
            }
        }
    }
}

struct DetailView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            DetailView(scrum: .constant(DailyScrum.sampleData[0]))
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

“这也是我正在关注的教程的链接:

https://developer.apple.com/tutorials/app-dev-training/passing-data-with-bindings

小智 8

看来您从一开始就遵循本教程,这是合乎逻辑的。然而,本课的项目文件包含对 DailyScrum.swift 的修改,其中定义 update() 如下。

mutating func update(from data: Data) {
    title = data.title
    attendees = data.attendees
    lengthInMinutes = Int(data.lengthInMinutes)
    theme = data.theme
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你!苹果的教程非常令人困惑,更不用说他们在幕后进行了更改。 (2认同)