Post

Replies

Boosts

Views

Activity

Reply to iOS: List selection is reset to nil when app is sent to background
I "fix" this by the save the selection to a temp variable onChange of the @Environment(.scenePhase) .onChange(of: scenePhase) { phase in             if phase == .background{                 tempSelectedId = selectedId             } else {                 if phase == .inactive && selectedId == nil{                     selectedId = tempSelectedId                     print("Restore - scenePhase")                 }             }         }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’23
Reply to iOS: List selection is reset to nil when app is sent to background
I "fix" this by the save the selection to a temp variable onChange of the @Environment(.scenePhase) .onChange(of: scenePhase) { phase in             if phase == .background{                 tempSelectedId = selectedId             } else {                 if phase == .inactive && selectedId == nil{                     selectedId = tempSelectedId                     print("Restore - scenePhase")                 }             }         }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’23
Reply to iOS: List selection is reset to nil when app is sent to background
I got the same problem. My situation is the code works fine on Mac and iPhone, no setting to nil on the background, but the problem occurs occasionally on the iPad (not every time, 1/3 I guess).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’23