1

At the moment I have a ForEach loop like this:

ForEach(viewModel.data, id: \.self) { data in
    Button(action: {

        self.isPresented.toggle()

    }, label: {
        
        HomepageRow(data: data)

    })
    .sheet(isPresented: $isPresented) {
        DetailView(data: data)
    }
}

And i need to pass data to my DetailView which has a var data: MyStruct this works fine, the problem is that when I tap back and I open another detailview, the new data is not passed. I know sheet doesnt trigger .onAppear of the mainView, so my question is, how do I pass different data based on the ForEach element tapped?


I can observe the same behavior with the new iOS 14.0 fullScreenCover.

This is the struct:

 }).fullScreenCover(isPresented: $isPresented) {
        print("DISMISSED")
 } content: {
      DetailView(data: data)
 }

So what is the best approach to pass new data once the sheet or fullScreenCover are dismissed?

pawello2222
  • 46,897
  • 22
  • 145
  • 209
manubrio
  • 419
  • 6
  • 16
  • 1
    @Asperi, can you check if you can close this as a duplicate? I believe one of your recent posts answers this question but I can't find it. – pawello2222 Sep 22 '20 at 20:08
  • This might help you: [iOS14 introducing errors with @State bindings](https://stackoverflow.com/questions/63928736/ios14-introducing-errors-with-state-bindings) – pawello2222 Sep 22 '20 at 20:35
  • 1
    Does this answer your question https://stackoverflow.com/a/63217450/12299030? – Asperi Sep 23 '20 at 04:15
  • Thanks a lot both!! I forgot about the sheet signature with item. THANKS @Asperi – manubrio Sep 23 '20 at 08:24

0 Answers0