|
Hey All, So I posted this a bit ago and took it down shortly after because I thought I had a solution to my problem. My solution wasn't a solution and has now sent me down a much larger rabbit hole than I started in. So, I have run into an issue where a piece of my UI doesn't update. I traced it back to the
But, since
How can I save the Thanks, Andy |
|
|
|
[https://www.hackingwithswift.com/forums/swiftui/persisting-textfield/24424/24426] Thanks Nigel! That did help quite a bit, but failed to resolve the core issue that I was experiencing with respect to updating a view based on the value. I've tried a few different iterations of the same thing, but ultimately, when the value changes in the I've tried a few different ways to make it work, including writting an
This chunk reads the value from a variable in a different file, which is updated when the user submits a new value to the To elaborate on this: The view will change state as appropriate when the app is closed and relaunched, but it will not change state when the variable is updated. Any ideas what I'm doing wrong? Thanks so much for your help. Andy |
|
Hi
And the other view
|
|
Hey @NigelGee So Hours() refers to the Hours() struct located in a different SwiftUI file.
I'm attempting to call Hours().totalHours from a different file in the same project. That file is where all information to the pilots hours-based experience lives. I did it this way because I have a variety of other calculations to do (time represented as a double, time represented on a calendar, validation represented as bools) and am segmenting them by file for ease of reference. The app will load the appropriate view at the launch of the app, but does not load the appropriate view when the Hours().totalHours value is updated. Here is ContentView:
The issue appears in the HeaderView file. The presents fine on in ContentView, but does not update. Here is the HeaderView file, only down to the first view that is not changing state (there are six, but the issue is mostly the same for all of them and they are all similar
Any help would be greatly appreciated with this. Is it because I have nested a view inside of a view inside of a view? Have I created a sort of... SwiftUI Inception? Thanks, Andy |
|
Think you got the it going the wrong way around.
Then the HeaderView
and what to navigation to Hours
|
|
@NigelGee Thanks for the help! That's not quite the solution that I found to work for me but it did lead me to the solution I needed. Effectively, I made a new Thank for all your help! Andy |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.