【发布时间】:2019-08-18 21:34:03
【问题描述】:
无法连同@Binding 对象一起初始化属性
我也尝试在结构体的 init() 方法中初始化它
struct WorkoutCard: View {
var numberOfWorkouts : [Int] = [0, 1, 2, 3]
@State var beginWorkout :Bool = false
var body: some View {
ZStack {
Rectangle().foregroundColor(Color.black)
if !self.beginWorkout {
ScrollView (.horizontal, showsIndicators: false) {
HStack {
ForEach(self.numberOfWorkouts.reversed(), id: \.self) { index in
Card(index, beginWorkout: $beginWorkout)
}
}
} }
}
}
}
//要初始化的视图
struct Card: View {
var number : Int
@Binding var beginWorkout : Bool
init(_ index: Int) {
self.number = index
}
}
错误 = 调用中的额外参数“beginWorkout”
【问题讨论】: