Friday, October 2, 2026
HomeiOS Developmentios - SwiftUI Picker onChange Response is unpredictable

ios – SwiftUI Picker onChange Response is unpredictable

[ad_1]

I made a picker like this;

However there’s a downside onChange doesn’t hearth at first choice.

indexList[0] have 0 as worth. When aside from 0 picked at Picker onChange doesn’t hearth
however at following alternatives it really works as it’s imagined to work.

Additionally when Picker checklist proven at first utilization, the primary merchandise ticked as it’s imagined to be. However when 2nd merchandise is chosen it doesn’t hearth onChange.

I couldn’t discover why.

Menu {
      Picker("", choice: $indexList[0]) {
         ForEach(0..<myArray.depend, id: .self) {  index in
              Textual content(myArray[index])
                    }
                }
             
                .onChange(of: indexList[0],
                          carry out: {_ in
                              dump(indexList[0])
                })
             
            } label: {
               customLabel0
            }



var customLabel0: some View{
    HStack {
      VStack(spacing: 10) {
        Textual content(labels[0])
          .foregroundColor(.black)
             Textual content(myArray[indexList[0]])
                   .multilineTextAlignment(.heart)
             }

           .foregroundColor(.white)
       }
       .body(width: (width, peak: peak)
       .background(Shade.grey)
       .cornerRadius(5)
   }
            

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments