SwiftUI: NavigationLink pops immediately if used within ForEach

后端 未结 1 332
情话喂你
情话喂你 2020-12-20 22:26

I\'m using a NavigationLink inside of a ForEach in a List to build a basic list of buttons each leading to a separate detail screen.

When I tap on any of the list ce

相关标签:
1条回答
  • 2020-12-20 22:34

    If you have a @State, @Binding or @ObservedObject in MainMenuView, the body itself is regenerated (menuItems get computed again) which causes the NavigationLink to invalidate (actually the id change does that). So you must not modify the menuItems arrays id-s from the detail view.

    If they are generated every time consider setting a constant id or store in a non modifying part, like in a viewmodel.

    0 讨论(0)
提交回复
热议问题