SwiftUI: Stepper Binding is not working in the subview

故事扮演 提交于 2021-02-11 15:12:35

问题


I have a stepper control in the main list view as well as in the detail view. the code is exactly the same. However the stepper in main view is working perfectly, but the subview is stopping after 1 increment (as it looks like the upper bound is set.) The funny thing is it was working some time ago, after improvements, i am not able to trace what exactly changed it s behaviour.

Here is the code.

struct QuestionCardTest: View {
    @Binding var question : SurveyQuestion

    var body: some View {

        NavigationLink(destination:QuestionCardDetailTest(question: $question)){
            HStack(spacing: 0){

                Text(question.questionText)
                Spacer()
                Text("\(self.question.ScaleInt) ")
                Stepper(value: self.$question.ScaleInt, in: 0...100)   {
                    Text("")
                }
            }
        }
    }
} 

struct QuestionCardDetailTest: View {

    @Binding var question : SurveyQuestion
    var body: some View {
        VStack
            {
                HStack{
                    Text("Answer (Numeric)")
                    Spacer()
                    Text("\(self.question.ScaleInt)")
                    Stepper(value: self.$question.ScaleInt, in: 0...100)   {
                        Text("")
                    }
                }
        }
    }
}

来源:https://stackoverflow.com/questions/59858800/swiftui-stepper-binding-is-not-working-in-the-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!