|
I want to be able to edit a post that the user has created. I am showing the created posts in a List, and once the user taps on a row it should open a view where the user can edit it. I am pushing the isActive variable because i am going to pop to the root from another view. Flow: Root (with the list of created posts) -> View to edit the post -> View to share the post (with button to go back to the root). The issue is that every time i tap on a row it pushes the view but the wrong post is loaded.
Any idea what I'm doing wrong? |
|
It's not clear from the code you shared. 1- Your first condition is better being 2- What is in your posts array? How is that populated. That might be where the issue lies. 3- For clarity purposes you might want to consider the NavigationLink line to be slightly different
4- You would also be better off having a separate View, or computed property or function to create each row. For simplicity I would use a function that returns I realize this does not directly answer your question, but the more information and clarity you provide to readers of your code, the better they can help! 😉 |
|
I agree with PS if it a |
|
Thank you for the replies: From the code below you can see how's it's loaded and it should be more clear:
The posts are loaded correctly in the List. The issue is that the navigationLink loads the wrong "post". |
|
Could it be that CreateNewPostView is where the problem is? It might have to do with something there! Also, which post gets shown? As in, what is the relationship between the post you click and the one that is shown. Is it the next one down the list? or is it some random post? In which case, you might want to try using a sort descriptor and seeing if that fixes the issue. |
|
Thank you for the reply. I think I found the issue, but I don't know how to fix it. I Will post my code again because I made some changes and it will make it easier for you:
If I remove the line:
This solves the issue but obviously I'm not able to dismiss the ViewC to go back to the rootView where this code is. This is the flow i need: rootView (where the list is), tap on a row -> ViewB, tap on a button -> ViewC, tap on a button -> pop to rootView |
|
I might be able to provide you with a link to that issue from an article I remember reading, I just need to sift through a bit to find it. Will update you as soon as I find it. |
|
Did you try this solution on this forum? It's a few months old, but might help. I couldn't find my link, but a quick search showed this: https://www.hackingwithswift.com/forums/swiftui/pop-to-parent-view-via-bar-button/1295 |
|
Thank you but I can't apply that to a row of the list. I tried the solution with NavigationLink(destination, tag, selection). I can't find a way to go back to the root. I created a sample project:
I would like to go back to the root (ContentView) using the button in the ColorDetail view but setting the selectedView to nil doesn't work |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.