所以我正在创建这个应用程序,用户可以在其中选择他希望练习的乘法表,以及第一个视图上的问题数量,然后按下按钮,
它继续传递这些数据的下一个视图,然后它将创建一个问题库供他做
有一个错误说我不能传递一个私有变量,为什么会这样?我已附上我的代码以供参考
import SwiftUI
struct ContentView: View {
@State private var multiplicationTable = 1
@State private var amountQuestions = 1
let multiplicationTables = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let amountQuestionss = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var body: some View {
NavigationView {
VStack {
Picker(selection: $multiplicationTable, label: Text("multiplicationTable")) {
ForEach(0 ..< 10) {num in
Text("\(multiplicationTables[num])")
}
}
.padding()
.padding()
Text("Choose number of Questions")
Picker("Select number of questions", selection: $amountQuestions) {
ForEach(0 ..< 10) {num in
Text("\(amountQuestionss[num])")
}
}
NavigationLink(destination: kek(One: multiplicationTable, Two: amountQuestions) .navigationBarHidden(true)) {
Button ("GO") {
}
.padding(50)
.background(Color.red)
.foregroundColor(.white)
.clipShape(Circle())
}
.navigationTitle("Choose Multiplication Table")
.navigationBarTitleDisplayMode(.inline)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
这是第一个视图,这是第二个视图
import SwiftUI
struct kek: View {
let One : Int
let Two : Int
@State var Question : String
@State var answer = ""
@State var Three = 0
@State var Four = 0
func nextQuestion(){
Three = One
Four = Int.random(in: 0...10)
Question = "\(Three) * \(Four)"
}
var body: some View {
VStack {
Text("Question: What is \(Question)?")
Form {
Section {
TextField("Amount", text: $answer)
.keyboardType(.decimalPad)
}
}
Button ("Next") {
}
.padding(50)
.background(Color.red)
.foregroundColor(.white)
.clipShape(Circle())
}
}
}
struct kek_Previews: PreviewProvider {
static var previews: some View {
kek(One: 1, Two: 2)
}
}