You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.
You should upgrade or use an alternative browser.
Swiftui navigationlink not working second time. Includes hands-on examples and pro tips.
- Swiftui navigationlink not working second time. In addition, I have included the logic responsible for handling long-living effects on views that are being presented on the stack in the demo app. When you navigate to another ViewA, you get a new NavigationStack that is nested in the existing one. (The shorter the TimeInterval of my timer the less the buttons are working) Nov 11, 2022 · The NavigationLink can’t be in the action of the button that is a void not a view builder Dec 27, 2020 · 3 I want to init a navigation stack in SwiftUI. First, let’s discuss the root view, or the first screen that will appear in your app. The list selection should be some data that represents what is being selected, not a view. Jun 2, 2021 · I´m creating an App and use NavigationLink in Swift/SwiftUI, but it doesn't work anymore. Feb 23, 2025 · NavigationLink is a SwiftUI component that allows users to navigate between views. When you run this code and click on the NavigationLink, ChildView doesn't update every second, even though… I am getting a warning about my NavigationLink. I am getting a warning about my NavigationLink. I post this in a HackingWithSwift forum and somebody tried the code May 13, 2023 · Explore the intricacies of SwiftUI NavigationView:NavigationLink, programmatically navigating, navigation bars, and navigation bar buttons. Imagine steering based on user interactions, not mere taps. simultaneousGesture () "attaches a gesture to the view to process simultaneously with gestures defined by the view. Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView Mar 17, 2025 · In this article, we’ll explore different navigation techniques in SwiftUI, including NavigationStack, NavigationLink, and NavigationDestination, and compare them with traditional UIKit approaches. I have tried many things and could not make it work. This includes going back to the … Nested NavigationLinks are not working properly in latest 13. The only way to get into A is to go to B Dec 14, 2021 · I think you should start your new research with Apple SwiftUI Tutorials there is a lot in your code that can make this not work. is it a bug or some code is missing in that example ? Apr 5, 2023 · My app supports iOS 15. Nov 29, 2023 · Hello community! I'm working on a silly little app to make a list of movies to eventually watch and just started getting this error: A NavigationLink is presenting a value of type “Movie” but there is no matching navigationDestination declaration visible from the location of the link. FirstView -> SecondView -> Third Oct 31, 2023 · We’re going to make it so that when the user taps on it we present them with a new view, and that’s done using NavigationLink: give this a destination and something that can be tapped, and it will take care of the rest. When a user interacts with a NavigationLink, SwiftUI automatically manages the navigation stack, pushing or popping views as needed. Similarly, if someone chooses the navigation link associated with a particular color, the list updates the selection value that other parts of your code can read. 5 is that the second set where the user can click to go see the overall results of the Quiz or Survey does not work when it's directly after the first navigation. We also get a message in console log like this: [SwiftUI] A NavigationLink is . Apr 27, 2021 · Where the issue is in 12. But, when going from the second to the third view, there's no transition. That said, you don't need this selection - since you are not driving the NavigationSplitView with a list, but with navigationDestination s. In this second one there is a Button that closes the view, going back to the first one. Tho A then A dose not work. With a couple of adjustments, you won't even need the lazy navigation link. The way I found to do this was with a NavigationLink with a destination and isactive and a closure of EmpytView. The list coordinates with the navigation logic so that changing the selection state variable in another part of your code activates the navigation link with the corresponding color. Jul 24, 2022 · I am working on a project that gathers real-time location data and stores it in a database (using google firebase). May 30, 2025 · If you have a NavigationLink or Picker that isn’t working, this usually happens because in some situations SwiftUI expects the containing view to be inside a NavigationStack. Apr 10, 2025 · Going from view 1 to view 2 work, the back arrow on view 2 is there, and it is working but the second time I go to the view 2, the back arrow is gone. Thanks! Feb 20, 2025 · I am adding an EventList to my app of CardViews but the List is not working properly. constant is a dead end, it should be used outside of previews, AnyView causes a lot to get lost, its use should be the exception. Mar 16, 2023 · Like the comment says this is not a bug it is design, if you inject in the upper most View that is shared such a NavigationStack, NavigationView, NavigationSplitView or TabVIew, etc. Each NavigationLink has a destination determined by the value given to Apr 20, 2025 · That works, but behind the scenes it causes SwiftUI to do more work than you might think — every time it creates a row in our List it will also create the NavigationLink, and as part of that it Aug 26, 2023 · In our exploration, we stumble upon the wondrous NavigationLink that bows to programmatic navigation. Simple and concise. I don't think it will work in this case though because my problem was that the child view's onDisappear executes after the root view's onAppear when going back in the navigation hierarchy. On iPadOS and macOS, the destination content appears in the next column. 3 (11C29) which I have reported to Apple. Oct 16, 2019 · The issue seems to lie in placing my NavigationLink inside of a navigationBarItems modifier that's nested inside of a SwiftUI view whose root view is a NavigationView. This wasn’t happening in iOS 16. common). 1 (macOS 15. This appears to work nicely. SwiftUI Tutorial: Working with NavigationView How to use NavigationLink in SwiftUI NavigationView allows a hierarchical way of moving from one view to another. Extending the flexibility, scalability, and cost benefits of AWS to all Apple and Swift developers, M4 instances deliver 20% better performance over previous generation M2. By ingeniously combining the behavior of Button with navigation logic, it dramatically simplifies code. Despite the documentation and numerous videos out there I've not really found a good answer for this as it pertains to nested views. However, the approach is not working (without modifications, see below). Still, a cool idea I'll be sure to use somewhere! Jun 11, 2024 · SwiftUI and NavigationLink - optional var in destination view is not initialising Asked 1 year, 2 months ago Modified 1 year, 1 month ago Viewed 68 times Users navigate to a destination view by selecting a NavigationLink that you provide. If I add sections the links are not working anymore, The view is not opening inside the detail view; why and ho Feb 11, 2024 · First, the list selection should not have type AnyView. 1) with SwiftUI and SwiftData, has a NavigationSplitView containing a List of NavigationLinks. Jan 20, 2024 · I have a view (NewGameView) with a NavigationLink to a different view (LoadView). Learn how to effectively use `NavigationLink` in SwiftUI while keeping button actions functional. One of the many things I love about SwiftUI is that we can use NavigationLink with any kind of destination view. SwiftUI uses the NavigationView to encapsulate the navigation structure. Mar 22, 2023 · There are many ways to pop a view out of a navigation view in SwiftUI. This article analyzes the cause of the problem and offers a practical—albeit slightly mysterious—solution SOLVED: How best to navigate to view of just added object Forums > SwiftUI SPONSORED Run your build pipelines on macOS in the cloud using the new Amazon EC2 M4 instances. then all the NavigationLink s will have access to the EnvironmentObject because it isn't the link sharing the object it is the upper most View. The buttons in toolbar / navigationbar do not work most of the time. May 4, 2023 · Why does the button "Show second view" not work here? struct ContentView: View { @State private var showSecondView = false var body: some View { NavigationSplitView { // Sidebar content irrelevant } detail: { if showSecondView { Text("Success!!"). Feb 24, 2025 · SwiftUI – Hacking with Swift forumsHi everyone, I recently updated my app to iOS 17, and I’ve noticed that NavigationLink sometimes doesn’t push the next view when tapped. It works fine on a real device. When i start the Timer which will refresh the view every 0,1 second only the button in the main view will work every time. Editing a list should not require navigating to another screen. NavigationLink(state:) (and NavigationLink(value:) for that matter) only work with the version of NavigationStack that takes a path binding. onAppear() on NavigationView root view but behave very differently: one is working correctly, the other incorrectly: import SwiftUI struct Child: View { var body: some View { Text("Child View") . NavigationLink is a view that provides a button that, when tapped, will navigate to another view. Mar 21, 2020 · Source: @bugsster on Unsplash If you’re new to iOS development and have just started working with SwiftUI you may know NavigationLink as the way you are able to transition between different Jan 26, 2020 · The button in second screen pops to first screen which works as expected, but as soon as I come back to first screen and I click NavigationLink, it does not move to second screen. Sep 11, 2020 · If I put NavigationLink around the button label instead of around the whole button, then, it goes to the second screen but button action stops working. Since my project become complicated, I just wanted to practice navigation in swiftui and I created a new project. It just needs a clear path and NavigationLink is the door. Learn more May 13, 2023 · SwiftUI’s NavigationView and NavigationLink provide a straightforward way to manage navigation in your apps. 0 Beta (13A5155e). Jul 28, 2021 · SwiftUI Navigation does not work as expected with 3 views when navigationLink to third view is embedded in a navigationBar button Asked 3 years, 8 months ago Modified 3 years, 8 months ago Viewed 2k times Sep 23, 2025 · Tags: swiftui swiftui-navigationview I am making an app where I take two number inputs and want to show the addition result of the numbers in the second screen, when a button is clicked. The NavigationLink with "Checkout" label does not work and the app just freezes when its tapped. We already used onTapGesture() in an earlier project, but there are several others, and there are also interesting ways of combining gestures together that are worth trying out. When the user clicks on the navigation link it shows a May 12, 2022 · If you want to override this behavior to make two gestures trigger at once, you should use the simultaneousGesture() when creating your second and subsequent gestures. I have a NavigationLink with destination: another view that applies filters to th Dec 25, 2024 · This destination is a new view. onTapGesture not recognized in a ForEach Forums > SwiftUI SPONSORED Run your build pipelines on macOS in the cloud using the new Amazon EC2 M4 instances. SOLVED: . This causes the problems you described ViewA should not contain a NavigationStack - it should just be the view you put inside the NavigationStack { }. I am relatively new to Swift but have been coding for about 2 years. The button to access the list is at the bottom of my stack. Tags: swiftui swiftui-navigationview I am making an app where I take two number inputs and want to show the addition result of the numbers in the second screen, when a button is clicked. Note: This problem only appears in simulator. Mar 15, 2023 · Start asking to get answers swiftui swiftui-navigationlink swiftui-navigationstack swiftui-navigationpath Dec 1, 2022 · SwiftUI does require that we pass some sort of view to NavigationLink even when doing programmatic navigation. Therefore I want to use a @State var, which I set to true onAppear, and thus activates a NavigationLink. Highlight doesn't work in the code below for me neither in Simulator nor device: Mar 26, 2025 · Navigation in SwiftUI doesn’t need to be a headache. If i remove the @Environment wrapper the issue goes away and everything works perfectly fine. Here is my simple app flow. onTapGesture () doesn't work. when selected the EventList appears but selecting the May 9, 2020 · Thanks for offering a suggestion. Nov 24, 2021 · SwiftUI’s NavigationLink has a second initializer that has an isActive parameter, allowing us to read or write whether the navigation link is currently active. Certain views, like NavigationLink views, already have built-in tap gesture detection, so . 5 does not agree with it. And the button was just one example. We can easily wrap a NavigationLink around a button, allowing us to make the entire button clickable and associate a navigation action with it. Apr 11, 2024 · NavigationLink { ItemDetail(item: item) } label: { That works, but behind the scenes it causes SwiftUI to do more work than you might think – every time it creates a row in our List it will also create the NavigationLink, and as part of that it will also create the ItemDetail for every visible row. 3 days ago · Here's a friendly breakdown of how to test Combine Publishers using the new framework, along with common pitfalls and alternative methods! Dec 13, 2022 · I am building an EV Station app on IOS, which provides users with a map and pins representing EV Charging Stations. after looking closely I can see the Arrow Underneath the S of SecondView. Here's the scenario View A is the root and contains the navigation stack as well as two nav linksView B is one level deep and can navigate back in two ways, 1 via the back button and 2 programatically triggered based on the dissmissal event of a modal M. Any help is greatly appreciated! Thank you and have a Mar 19, 2025 · SwiftUI navigation made simple! Learn best practices for using NavigationStack, NavigationLink, and NavigationPath to create seamless app flows. Feb 7, 2020 · 2 This is a simulator bug only, if you have a device to test on the NavigationLink works correctly multiple times. The NavigationLinks which already are in th Jul 5, 2019 · There seems to be a bug with the navigation link in Xcode version 11. Like I said before hand it worked perfectly in 12. Extending the flexibility, scalability, and cost benefits of AWS to all Apple and Swift developers, M4 instances deliver 20% better performance over previous When my timer doesn't update "number" all 3 buttons are working properly. Please keep content related to SwiftUI only. Hopefully Apple will fix this soon. navigationTitle("Why does this not work?") }} This code creates the following: Why doesn't View 2 show a . struct ViewA: View { let someText: String? let someNumber: Int? @Binding var May 23, 2023 · NavigationStack in Use To effectively illustrate the process of implementing NavigationStack in SwiftUI, let’s break down our exploration into three code examples. What's most puzzling is that if you comment out the ForEach, it works as expected. Thanks to @djr The below code works as expect the first time you use the navigation link. Feb 8, 2024 · Here I want to make sections in side the navigation SideBar of a NavigationSplitView. Perfect for developers of all skill levels looking to enhance their app's user experience. Learn how to create, customize, and implement dynamic navigation patterns with easy-to-understand examples. You’ll probably want to use EmptyView to show nothing at all, for example here’s a complete example of programmatic navigation, where I’m toggling the Boolean on a button press: Sep 2, 2022 · I want to invoke another view programmatically. Plus, this being only an iOS 18 issue and other links working correctly makes me believe that there should be another solution, right? Jan 30, 2024 · This is not working for me when I have a NavigationStack(path:root:) that uses NavigationLink(_ titleKey:value:) and navigationDestination(for:destination). 4 but seems like 12. If the types differ then navigation will not work as shown in the example below. Mixing both approaches does not work. If you navigate to a nested NavLink, then return one level, NavigationLink Views turn Aug 19, 2019 · Turns I did not get my NavigationLink to be enabled because the toggling did not work, not because of incorrect usage of the booleans and disabled view modifier. When I click back and then click the Get Started button again, it does not work a second time. Unlock the power of navigation in your SwiftUI apps with our comprehensive guide on NavigationLink. This works wonderfully, unt Feb 28, 2022 · VIEW 2: (Separate file) struct HomepageView: View { var uid: String var body: some View { VStack { Text("Hey, \(uid)") } . Consider an add button in the navigation header or some other means of allowing the user to add a list item. autoconnect Dec 17, 2023 · The issue is that you are mixing two different approaches two navigation, the "old" one with NavigationLink(destination:) and the "new" one NavigationLink(value:). So, I've added NavigationView and used NavigationLink for navigation. When I Learn about the navigation stack, links, and how to manage navigation types in your app’s structure. Other platforms push a new view onto the stack, and enable removing items from the stack with platform-specific controls, like a Back button or a swipe gesture. " Dec 11, 2019 · I found this flow Why does my SwiftUI app crash when navigating backwards after placing a `NavigationLink` inside of a `navigationBarItems` in a `NavigationView`? but i could not solve my problem. I hope this will help someone when struggling with similar issues. The link does not work, though the button does, as proved by the print statement (see below). The basic usage of NavigationLink is as follows: Sep 14, 2022 · I'm attempting to use @EnvironmentObject to pass an @Published navigation path into a SwiftUI NavigationStack using a simple wrapper ObservableObject, and the code builds without issue, but working with the @EnvironmentObject has no effect. This has been a problem in one way or another on every version of Jun 21, 2023 · Ever been using NavigationLink inside a NavigationView and got this deprecation warning in Tagged with swift, ios, xcode, swiftui. SwiftUI provides a special button called NavigationLink, which can detect user taps and trigger the navigation presentation. Apr 26, 2022 · Granted, we could just use that NavigationLink instead, but the question was how we achieve navigation with EmptyView and isActive. It Jul 10, 2025 · In SwiftUI, when I place multiple NavigationLink views directly inside a HStack, then put this HStack inside a List, clicking one link triggers all NavigationLink views, causing unexpected navigat Mar 7, 2024 · The problem is that the NavigationStack is part of ViewA. Feb 21, 2024 · SwiftUI gives us lots of gestures for working with views, and does a great job of taking away most of the hard work so we can focus on the parts that matter. Running on device, instead of simulator made everything work! But I still see the warning message as soon as I press any Toggle (but only once): For SwiftUI discussion, questions and showcasing SwiftUI is a UI development framework by Apple that lets you declare interfaces in an intuitive manner. Apr 3, 2020 · Selection in NavigationLink is not working Asked 5 years, 1 month ago Modified 5 years, 1 month ago Viewed 949 times Dec 16, 2022 · I have one navigationLink in the view but for the very first time its not clickable, but when i copy pasted same code below that the second navigationLink is working properly, I am not sure what is Aug 16, 2024 · That's weird, I have NavigationLink all over the app and I never use NavigationStack. Sep 11, 2020 · NavigationLink is not intended to work when in edit mode. modelContext) private var context. 0 so, I can not use NavigationPath. Mar 29, 2022 · SOLVED: NavigationLink issue updating both views when item changes Forums > SwiftUI SPONSORED Run your build pipelines on macOS in the cloud using the new Amazon EC2 M4 instances. SwiftUI empowers you: import SwiftUI May 9, 2023 · When a user is navigated to the Second_View, thats exactly what happens and works fine. navigationTitle("Child") } } struct ContentView: View { @State var timerEventChangeThis = 0 private let timer = Timer. Sep 22, 2023 · Merging Navigation Links and Buttons The big question now is, how do we combine these two to achieve our desired functionality? The solution is in SwiftUI’s flexibility. Here is the code that caused the warning: @Environment(\. So A then B then A works fine. main, in: . I have a navigation stack that shows a list of words. Result of 'NavigationLink<Label, Destination>' initializer is unused Below I have included the code that has caused the warning and the code of the target of the Navigation link. navigationDestination(for:) for the Mar 5, 2024 · However, you want to be careful when you use this modifier, because it can easily turn into a really bad practice! So let’s take a look at a couple of use cases. It was working properly until I updated XCODE to 16 Nov 29, 2019 · I got a NavigationView, trying to navigate into a NavigationLink for a second time without luck. Demystify SwiftUI might help clear stuff up too. Jan 30, 2021 · I've been running into a hairy problem with SwiftUI that I've managed to condensed down into this simple example. Nov 25, 2019 · NavigationLink is essentially a button so it responds to touches, when you add a tap geture onto it you have a single view that is trying to respond to two touches at the same time. Thus I want to push a second view immediately after a first view appears. Apr 21, 2021 · Two seemingly identical . It is the simplest way to manage navigation and has been around since SwiftUI's introduction. In this first use case, we use the modifier . Unfortunately it becomes unresponsive the second time around. Unfortunately, in certain scenarios, using it the wrong way can create serious performance issues and make your app sluggish. Includes hands-on examples and pro tips. This issue is a common pitfall for developers using SwiftUI's navigation, especially when working with complex data models or view hierarchies. run on iPhone/ iOS no problem run on a Mac/macOS Going from view 1 to view 2 work, the back arrow on view 2 is there, and it is working but the second time I go to the view 2, the back arrow is gone. navigationTitle("Second View") } else { NavigationStack { NavigationLink("Subview") { Button("Show second view") { showSecondView = true Apr 29, 2025 · NavigationLink is a component SwiftUI developers love. Secondly, the types you pass to navigationDestination(for:destination:) should be the types of your data. Dec 26, 2020 · There are many ways to interact with different screens (views), here I'll cover them all with examples and pictures. Below I have included the code that has caused the warning and the code of the target of the Navigation link. Nov 17, 2020 · The whole concept relies on separating the state of the view that is being presented from the state that determines if the corresponding SwiftUI NavigationLink is active. Aug 8, 2025 · Here's an explanation of why NavigationLink can sometimes break your NavigationSplitView and how to fix it. When the NavigationLink content Mar 5, 2025 · SwiftUI’s navigation system is built on a declarative model, where you define what you want to see, not how it should be done. In IOS 16 this became Feb 20, 2022 · 2 You're working against a couple of the principals of SwiftUI just enough that things are breaking. Apr 3, 2020 · SwiftUI’s NavigationLink has a second initializer that has an isActive parameter, allowing us to read or write whether the navigation link is currently active. This guide provides a clear solution to common navigation i I'm running into this error, when the underlying SwiftData object changes: *" A NavigationLink is presenting a value of type “Project” but there is no matching navigationDestination declaration visible from the location of the link. Oct 2, 2024 · I have two tabs on the top, in each tab list of cards are shown and each card has a navigation link which is used to navigate to the detail view. The link cannot be activated. navigationTitle ? I have been stuck on this for a long time now. This is true of vanilla SwiftUI, it's not an issue with TCA. I can print the result in the console, but unfortunately it seems like navigation link is not working, around the button. In this view, we create a NavigationStack and List of NavigationLink s. That is a cool idea and I should try it sometime. When you run this code and click on the NavigationLink, ChildView doesn't update every second, even though it seems that it should. Extending the flexibility, scalability, and cost benefits of AWS to all Apple and Swift developers, M4 instances deliver 20% better performance over previous generation M2 Mar 13, 2024 · Hi @IDTIMW, you cannot use NavigationLink(state:) with navigationDestination(item:). Here is my code: Feb 5, 2020 · This almost works. publish(every: 1, on: . I don't Feb 19, 2024 · I am new to SwiftUI and I am simply experimenting with different NavigationStack options. With these tools, you can easily create complex navigation hierarchies with minimal code. Which technique to use is based on the iOS version you supported and how you structure your view. You will have to decide to either only use the links where you directly define the destination or the one where you define a value and then later on define a . I don't now since when, but 2 or 3 weeks ago, all working fine. NavigationStack’s value parameter and navigationDestination’s for parameter must be of same type. For example, in this code we have two tap gestures, but SwiftUI will execute only the one attached to the circle because it’s the child of the VStack: Nov 15, 2024 · The boiler plate code for a Multiplatform app on Xcode 16. Oct 31, 2022 · Description For programatic navigation you could previously use NavigationLink(isActive:, destination:, label:) which would fire navigation when the isActive param is true. onTapGesture() to start pre-fetching some data over the network when the user taps on a View. Take a note on the value that was passed from NavigationLink to navigationDestination and it was displayed on the detail view. It works randomly, but sometimes I have to tap multiple times. y1d6 afab u7nfy5c c9o oauqy 6f3lptz 7rr jp0h4vn zc 5hp