DESCRIPTION OF PROBLEM
I have changed my app to the @Observable-Macro. When using an iPhone (on simulator and on real device) the navigation from a player to the player detail view and back breaks. In the attached video on my GitHub you can see me tapping on both players in the team, but the navigation ist not showing the detail view.
What is the reason? Is my usage/understanding of @Observable wrong? Is it wrong to have the selectedPlayer within the PlayerController which is @Observable? And why does it sometimes work and sometimes not?
The project can be found here: GitHub Project
STEPS TO REPRODUCE
-
Start the App, add one or two demo teams, tap on a team and add two or more demo players.
-
tap a player and then go back, tap the player again and back again. After a while (number of taps is always different), the navigation breaks. See my video attached.
PLATFORM AND VERSION
iOS Development environment: Xcode 15.4, macOS 14.5 (23F79) Run-time configuration: iOS 17.5,
It appears that the list selection does not reliably reset to nil when tapping the “back” button.
List(selection: $teamController.selectedTeam) {.....}
To address this, I added an onAppear modifier to force the list selection to reset to nil.
List(selection: $teamController.selectedTeam) {.....}
.onAppear {teamController.seletedTeam = nil}
This resolved the issue for both the team and player lists.
However, it would be helpful if someone could explain why the list selection doesn’t automatically reset to nil when tapping the back button.