You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -433,20 +433,15 @@ This time the transition animation involves the whole screen:
433
433
434
434
## Issues
435
435
436
-
- SwiftUI resets all the properties of a view marked with `@State` every time the view is removed from a view hierarchy. For the `NavigationStackView` this is a problem because when I come back to a previous view (with a pop operation) I want all my view controls to be as I left them before (for example I want my `TextField`s to contain the text I previously typed in). It seems that the solution to this problem is using the `.id` modifier specifying an id for the views I don't want SwiftUI to reset. According to the Apple documentation the `.id` modifier:
437
-
438
-
> Summary
439
-
> Generates a uniquely identified view that can be inserted or removed.
440
-
441
-
but again, it seems that this API is currently not working as expected (take a look at this interesting post: https://swiftui-lab.com/swiftui-id/). In order to workaround this problem, then, you have to use `@ObservableObject` when you need to make some state persist between push/pop operations. For example:
436
+
- SwiftUI resets all the properties of a view marked with `@State` every time the view is removed from a view hierarchy. For the `NavigationStackView` this is a problem because when I come back to a previous view (with a pop operation) I want all my view controls to be as I left them before (for example I want my `TextField`s to contain the text I previously typed in). In order to workaround this problem you have to use `@ObservableObject` when you need to make some state persist between push/pop operations. For example:
442
437
443
438
```swift
444
439
classViewModel: ObservableObject {
445
440
@Publishedvar text =""
446
441
}
447
442
448
443
structMyView: View {
449
-
@ObservedObjectvar viewModel=ViewModel()
444
+
@ObservedObjectvar viewModel: ViewModel
450
445
451
446
var body: some View {
452
447
VStack {
@@ -461,4 +456,4 @@ struct MyView: View {
461
456
462
457
### Other
463
458
464
-
SwiftUI is really new, there are some bugs in the framework (or unexpected behaviours) and several API not yet documented. Please, report any issue may arise and feel free to suggest any improvement or changing to this first implementation of a navigation stack.
459
+
SwiftUI is really new, there are some unexpected behaviours and several API not yet documented. Please, report any issue may arise and feel free to suggest any improvement or changing to this implementation of a navigation stack.
0 commit comments