This question already has answers here:
Can't Add More Than 10 Items to View SwiftUI [duplicate]

(3个答案)


在10个月前关闭。




我在SwiftUI的切换开关上不断收到“在调用中的位置11,#12处有其他参数”错误。我已经看到其他人有“通话中的额外参数”错误,但是答案似乎并没有帮助。另外,我的错误是“职位11、12”,这是我所没有见过的。我正在使用Xcode 12 beta,如果有帮助的话。
import SwiftUI

let defaults = UserDefaults.standard

let notifsEnabled = defaults.bool(forKey: "NotifsEnabled")




struct Settings: View {
    @State var class11: String = defaults.string(forKey: "class11") ?? ""
    @State var class12: String = defaults.string(forKey: "class12") ?? ""
    @State var class13: String = defaults.string(forKey: "class13") ?? ""
    @State var class14: String = defaults.string(forKey: "class14") ?? ""

    @State var class21: String = defaults.string(forKey: "class21") ?? ""
    @State var class22: String = defaults.string(forKey: "class22") ?? ""
    @State var class23: String = defaults.string(forKey: "class23") ?? ""
    @State var class24: String = defaults.string(forKey: "class24") ?? ""

    @State var scheduleNotifications = notifsEnabled



    var body: some View {

        VStack(alignment: .leading) {

            Toggle(isOn: $scheduleNotifications) { //Extra arguments at positions #11, #12 in call
                Text("Daily schedule notifications")
            }

            if scheduleNotifications {
                Text(CreateNotifs())
            } else {
                Text(DeleteNotifs())
            }



            Text("This App will send you a reminder each day at 8:25 with the schedule for that day")
                .font(.caption)
                .foregroundColor(Color.gray)


            Divider()

            TextField("Class 1-1", text: $class11)

            TextField("Class 1-2", text: $class12)

            TextField("Class 1-3", text: $class13)

            TextField("Class 1-4", text: $class14)

            TextField("Class 2-1", text: $class21)

            TextField("Class 2-2", text: $class22)

            TextField("Class 2-3", text: $class23)

            TextField("Class 2-4", text: $class24)



            //Spacer()
        }
        .padding()
        .navigationBarTitle("Settings")

    }

}






最佳答案

ViewBuilder在一个容器中仅支持不超过10个静态 View ...这就是您出错的原因
只是把他们分组

Group {

    TextField("Class 1-1", text: $class11)

    TextField("Class 1-2", text: $class12)

    TextField("Class 1-3", text: $class13)

    TextField("Class 1-4", text: $class14)

    TextField("Class 2-1", text: $class21)

    TextField("Class 2-2", text: $class22)

    TextField("Class 2-3", text: $class23)

    TextField("Class 2-4", text: $class24)

}

关于swift - 调用SwiftUI的#11,#12处的额外参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62820488/

10-10 08:47