1

I can't make many .scrollTo() in my code: (I'm French sorry for my bad english)

else if index == 1 {
    withAnimation {
            value.scrollTo(topID)
     }
}

my issue is in value.scrollTo(topID) I tried to implement 6 of them in 3 differents foreach and The compiler doesn't compile but if I remove the value.scrollTo(topID) of one of the Foreach it compile

else if wichView.SelectedView == 5 {
            HStack {
              ForEach(1..<6) { index in
                Spacer()
                Button(action: {
                  if index == 3 {
                    withAnimation() {
                      wichView.SelectedView = 1
                      wichView.carouselLocation = 0
                    }
                    value.scrollTo(topID)
                  }
                  else if index == 1 {
                    withAnimation {
                      value.scrollTo(topID)
                    }
                  }
                },
                label: {
                  Image("IPPV5_TABBITEM\(index)")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 40,
                        height: 40)
                })
              }
              Spacer()
            }
            .padding(.bottom, -10)
            .frame(width: size.width,
                height: 35)
          }
          else if wichView.SelectedView == 6 {
            HStack(spacing: size.width/3 - 10) {
              Button(action: {
                withAnimation {
                  value.scrollTo(topID)
                }
              },
              label: {
                Image("IPPV6-TABITEM1")
                  .resizable()
                  .aspectRatio(contentMode: .fit)
                  .frame(width: 40,
                      height: 40)
                 
              })
               
              Button(action: {
                wichView.SelectedView = 1
                wichView.carouselLocation = 0
                value.scrollTo(topID)
              },
              label: {
                Image("IPPV6-TABITEM2")
                  .resizable()
                  .aspectRatio(contentMode: .fit)
                  .frame(width: 40,
                      height: 40)
              })
              Spacer()
            }
            .padding(.bottom, -10)
            .frame(width: size.width - 40,
                height: 35)
          }
          else if wichView.SelectedView == 8 {
            IPPV8TabItem
          }
          else if wichView.SelectedView == 9 {
            HStack {
              ForEach(1..<6) { index in
                Spacer()
                Button(action: {
                  if index == 3 {
                    withAnimation {
                      wichView.SelectedView = 1
                    }
                    wichView.carouselLocation = 0
                   // withAnimation {
                   //  value.scrollTo(topID)
                   // }
                  }
                  else if index == 1 {
                   // withAnimation {
                   //  value.scrollTo(topID)
                   //}
                  }
                },
                label: {
                  Image("IPPV9-\(index)")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                })
              }
              Spacer()
            }
            .frame(width: size.width,
                height: 40)
          }

This is Part of my code (all is in a ScrollView who is in a Scrollviewreader who is in a Vstack who is in a Zstack)

This code work fine and compile because I commented the .scrollTo() of one of the Foreach if I decomment it will not compile.

Any help please I don't know if the problem is the Foreachs or the .scrollTo()?

Name
  • 11
  • 1

1 Answers1

0

Finally I did something like else if wichView.SelectedView == 9 && wichView.SelectedView == 5 to merge both conditions and use the same .scrolLTo it works so I don't understand why it does not compile before in different Foreach

Name
  • 11
  • 1