|
Hi I have a picker displaying the contents of an array and a "special" selection at the top of the list. What I want is for the app to go to AddNewItemView() when the user selects the top item. I have been trying to do this using a NavigationLink:
There are problems with the syntax of the NavigationLink which I have been unable to resolve:
Can the syntax be sorted out, or, is there a better way to do what I want to do? Cheers John |
|
I think there are a few problems with your use of First, the Second, the Third, your destination parameter must be passed as a closure, similar to how you specify the label:
But in the end: I doubt that you want this form of Probably |
|
Here is how I made your example work
|
|
Hi @pd95 Thanks for your reply, suggestions and extra code. My example was a simplified piece of code from a coredata app I am writing where the “item” has a name, description and other attributes. I used your code and it works fine. I also experimented with using NavigationLink(isActive:, destination:, label:) and found that it also works and is simpler and more obvious code, so would be preferable. Your solution of DispatchQueue with the 0.5s delay and using NavigationLink(isActive:...) both have the app returning to “MyPickerView” (displaying “Add New Item”) before bringing up the AddNewItem view. Unfortunately, although this is functional, from a user experience perspective in a production app, it would annoy me! You also showed a solution for getting the new item back into the selectedItem variable which I knew needed to be solved and was going to be my next “project”. Thank you for that. So I think I am back to the drawing boards to look for another way to present a user with a (picker) list and if they cannot find the item they want in that list, (somehow) go to an AddNewItem view. Thanks again and I will mark this as solved. Cheers |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
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.