Questions tagged [swiftui-navigationlink]

For questions about NavigationLink - a component in Apple's SwiftUI framework that triggers a navigation presentation when pressed. When using this tag also include the more generic [swiftui] tag where possible.

Filter by
Sorted by
Tagged with
143 votes
14 answers
19k views

SwiftUI - how to avoid navigation hardcoded into the view?

I try to do the architecture for a bigger, production ready SwiftUI App. I am running all the time into the same problem which points to a major design flaw in SwiftUI. Still nobody could give me a ...
Darko's user avatar
  • 9,765
106 votes
5 answers
18k views

NavigationLink Works Only for Once

I was working on an application with login and after login there are categories listed. And under each category there are some items listed horizontally. The thing is after login, main page appears ...
C.Aglar's user avatar
  • 1,309
38 votes
4 answers
15k views

How to disable NavigationView push and pop animations

Given this simple NavigationView: struct ContentView : View { var body: some View { NavigationView { VStack { NavigationLink("Push Me", destination: Text("...
kontiki's user avatar
  • 39.1k
35 votes
10 answers
18k views

SwifUI onAppear gets called twice

Q1: Why are onAppears called twice? Q2: Alternatively, where can I make my network call? I have placed onAppears at a few different place in my code and they are all called twice. Ultimately, I'm ...
AvsBest's user avatar
  • 465
29 votes
2 answers
56k views

SwiftUI Error: "Closure containing control flow statement cannot be used with function builder 'ViewBuilder'"

I tried a SwiftUI tutorial, "Handling User Input". https://developer.apple.com/tutorials/swiftui/handling-user-input I tried implementing it with for instead of ForEach. But an error arose: &...
msoniku's user avatar
  • 291
28 votes
2 answers
5k views

SwiftUI NavigationView trying to pop to missing destination (Monoceros?)

I'm using Xcode 12 with deployment for iOS 14.0. My home screen has a NavigationView Within the NavigationView there is a TabView (with 4 tabs) Within each tab are subviews that have buttons and ...
nicksarno's user avatar
  • 4,085
27 votes
2 answers
14k views

SwiftUI List is not showing any items

I want to use NavigationView together with the ScrollView, but I am not seeing List items. struct ContentView: View { var body: some View { NavigationView { ScrollView{ ...
Winten's user avatar
  • 634
26 votes
6 answers
12k views

SwiftUI NavigationLink pops out by itself

I have a simple use case where a screen pushes another screen using the NavigationLink. There is a strange behaviour iOS 14.5 beta (1, 2, 3), where the pushed screen is popped just after being pushed. ...
Jan's user avatar
  • 7,574
26 votes
9 answers
15k views

SwiftUI List disclosure indicator without NavigationLink

I am searching for a solution to show the disclosure indicator chevron without having the need to wrap my view into an NavigationLink. For example I want to show the indicator but not navigate to a ...
grahan's user avatar
  • 2,318
22 votes
1 answer
14k views

'init(destination:isActive:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a NavigationStack or NavigationSplitView

I have tried different iterations of examples posted on this site but nothing is going right. I have also tried following the examples listed here: Navigation to new navigation types: I am getting the ...
LizG's user avatar
  • 2,448
20 votes
5 answers
20k views

NavigationLink isActive deprecated

In the new version of iOS and Xcode NavigationLink(isActive: , destination: , label: ) is deprecated. How do we control the status of NavigationLink then?
Steven-Carrot's user avatar
18 votes
2 answers
6k views

SwiftUI Navigation Multiple back button

When I push more than one view, multiple back buttons are visible in the navigation bar. struct ContentView: View { var body: some View { NavigationView { NavigationLink(...
Stefano Toppi's user avatar
18 votes
2 answers
4k views

SwiftUI .toolbar disappears after following NavigationLink and coming back

I've added a .toolbar to the top level of a NavigationView that will eventually be used to select items in a list without using swipe gestures (up button, down button, etc.). I also have a ....
SunriseHurts's user avatar
17 votes
3 answers
10k views

SwiftUI NavigationLink Bug (SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug.)

Console Bug: SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug. There is no problem when I don't use the isActive parameter in NavigationLink. However, I have to use the ...
Ufuk Köşker's user avatar
17 votes
4 answers
10k views

How do you fix Xcode 14 warning: NavigationLink presenting a value must appear inside a NavigationContent-based NavigationView. Link will be disabled

Since installing Xcode 14, I am now getting the following error message printed in my console: NavigationLink presenting a value must appear inside a NavigationContent-based NavigationView. Link will ...
xanderbuck's user avatar
15 votes
3 answers
4k views

SwiftUI NavigationLink memory leak

I have a question on how memory management works in SwiftUI's NavigationView stack. I have a view, in which I have declared NavigationView and NavigationLink, inside destination parameter of ...
Róbert Oravec's user avatar
14 votes
1 answer
12k views

Use NavigationLink programmatically in SwiftUI

I'm looking for a way to display a view in my WatchOS application "one level in" from the NavigationView on app startup if certain conditions are met. I want the same effect as if I would have ...
heinz_dieter's user avatar
14 votes
9 answers
10k views

Runtime error: precondition failure: attribute failed to set an initial value

I have a view BugSplitView which works fine alone but causes a precondition failure: attribute failed to set an initial value error when navigated to in either preview or the simulator. The view ...
Rumbles's user avatar
  • 838
14 votes
1 answer
6k views

Create a SwiftUI Sidebar

I want to build a very simple iOS 14 sidebar using SwiftUI. The setup is quite simple, I have three views HomeView, LibraryView and SettingsView and an enum representing each screen. enum Screen: ...
jlsiewert's user avatar
  • 3,534
14 votes
1 answer
958 views

SwiftUI: Adding .onDrag blocks clicking/selecting an item in the macOS sidebar

I have a list in my macOS app’s sidebar. When I add the .onDrag modifier, dragging NSItemProvider works correctly, but clicking/selecting the item to trigger the NavigationLink gets blocked. struct ...
Frank R's user avatar
  • 861
14 votes
1 answer
11k views

How to use variable inside the body of the view using swiftUI?

i'm trying to using a variable and modify inside the foreach of swiftui. below are the code i'm using. please let me know how can i modify the value inside the body of the view. struct SearchView : ...
Sourav Mishra's user avatar
13 votes
2 answers
8k views

SwiftUI - List / ForEach in combination with NavigationLink and isActive doesn't work properly

I'm trying to do a NavigationLink within a List or ForEach Loop in SwiftUI. Unfortunately I get a really weird behavior (e.g. when clicking on Leo it opens Karl, Opening Max points to Karl, too). I've ...
SwiftUIRookie's user avatar
13 votes
2 answers
7k views

Using NavigationLink in Menu (SwiftUI)

Can you use a NavigationLink as a Menu's item in swiftUI? It seems to do just nothing: Menu { NavigationLink(destination: Text("test1")) { Text("item1") } ...
Leo's user avatar
  • 1,690
13 votes
2 answers
12k views

SwiftUI custom animated transition in navigationView?

is there a way in SwiftUI to change the standard behaviour of NavigationView/NavigationLink, which is to slide from one view to the next? I'd like to have a custom animation/transition like fade in/...
jboi's user avatar
  • 11.6k
12 votes
2 answers
9k views

Is there a way to add an extra function to NavigationLink? SwiftUI

I would like to add an extra function to the NavigationLink. example code is something like this: struct ContentView: View { func yes () { print("yes") } var body: some View { NavigationView { ...
I Kaya's user avatar
  • 427
12 votes
3 answers
3k views

SwiftUI Navigation popping back when modifying list binding property in a pushed view

When I update a binding property from an array in a pushed view 2+ layers down, the navigation pops back instantly after a change to the property. Xcode 13.3 beta, iOS 15. I created a simple demo and ...
lacking-cypher's user avatar
12 votes
3 answers
7k views

Why does NavigationLink buttons appear "disabled" in a custom UIViewControllerRepresentable wrapper

I have created a wrapper that conforms to UIViewControllerRepresentable. I have created a UIViewController which contains a UIScrollView that has paging enabled. The custom wrapper works as it should. ...
Osama Naeem's user avatar
  • 1,900
12 votes
5 answers
12k views

How to Navigating from SwiftUI View to UIKit UIViewController

As of now, I have an application built entirely using UIKit. However, I wish to be able to start implementing some SwiftUI Views to replace some UIViewControllers. I've been able to do this to ...
Chiah Soon's user avatar
12 votes
2 answers
4k views

@EnvironmentObject doesn't work well through navigationLink

I use my @EnvironmentObject to let my TeamData can use by different but it doesn't work well. When I go to another view by navigationLink in List, it's fine. When I tap a button to the same View, it ...
frank61003's user avatar
12 votes
1 answer
3k views

Supporting SwiftUI navigation in legacy projects

I'm wondering if there's any way to start using SwiftUI in a legacy project and still be able to navigate back and forth SwiftUI scenes. That is, let's imagine I just want to support the last iOS 13 ...
Fernando's user avatar
  • 771
11 votes
2 answers
8k views

How can I initialize View Again in SwiftUI?

I’m using SwfitUI in my project and I have a NavigationView and List. I’m clicking cell after open the detail view and click navigation back button. I want to remove view (it’s struct, in SwiftUI) ...
Erkam KUCET's user avatar
11 votes
1 answer
1k views

SwiftUI List rows in Edit Mode do not allow Buttons actions/NavigationLinks to work?

SwiftUI List rows in Edit Mode do not allow Buttons actions to work I note (as well as NavigationLinks too). Is there a way to get this working? Goal - Want to have NavigationLink or Modal view to ...
Greg's user avatar
  • 34.5k
11 votes
1 answer
2k views

NavigationLink freezes when trying to revisit previously clicked NavigationLink in SwiftUI

I am designing an app that includes the function of retrieving JSON data and displaying a list of retrieved items in a FileBrowser type view. In this view, a user should be able to click on a folder ...
Vapidant's user avatar
  • 2,612
11 votes
2 answers
1k views

How can I unwind to the MainView in SwiftUI

I can't find a way to go to the ContentView from ViewB without showing a secound NavigationView on top of the other NavigationView. struct ContentView: View { var body: some View { ...
crashboy's user avatar
  • 123
10 votes
1 answer
11k views

SwiftUI TextField takes max width

I have a navigation list with each list item being in this format: HStack { TextField("Insert something here.",text: self.$userData.pages[i].title) .border(Color.blue) ...
user4500882's user avatar
10 votes
1 answer
7k views

SwiftUI navigation titles within TabView

For the reason outlined in the answer outlined in this question SwiftUI TabView brightness views vertical location the menu structure for my app is NavigationView -> TabView -> sub view with ...
John Sorensen's user avatar
10 votes
1 answer
983 views

SwiftUI: NavigationLink pops out immediately on WatchOS 8.1RC in Tabview

I have discovered a regression in watchOS 8.1RC with NavigationLink triggered from a TabView. It's immediately dismissed. It was working in watchOS 8.0 or in Simulator (watchOS 8.0). Do you know a ...
Raphaël Barthomeuf's user avatar
10 votes
2 answers
846 views

Use match geometry effect when navigating between views using a navigation link

My home view contains a CustomView that opens a detailed view via a NavigationLink when tapped. The detailed view also contains the CustomView, just in a different location. Can I use the match ...
yambo's user avatar
  • 1,667
9 votes
2 answers
7k views

How to change NavigationLink arrow color within Form

In SwiftUI, when a NavigationLink is placed inside of a Form, an arrow automatically appears on the trailing side of the NavigationLink. How can the color of this arrow be changed? struct example: ...
Ryan's user avatar
  • 660
9 votes
1 answer
2k views

SwiftUI's NavigationView Is Missing The Back Button On Apple Watch

I created an Apple Watch app using SwiftIU. The main view of the app is a List, with NavigationLink to another List. When I'm in one of the internal Lists, the back button isn't on the top of the view....
Shahar Melamed's user avatar
9 votes
4 answers
2k views

Incomplete Swipe-back gesture causes NavigationPath mismanagement

I am looking for solutions to the following bug in my example code below. I have tried to implement the Navigator Pattern with SwiftUI 4 and the iOS 16.0 Navigation API changeset. The example below ...
Andre's user avatar
  • 672
9 votes
4 answers
6k views

Set Color of Chevron in a SwiftUI List in a NavigationView

I have this list I a NavigationView. In dark mode the Chevron (red circle) is almost invisible. How can I set the Color of Chevron in a List. struct ContentView: View { var body: some View { ...
mica's user avatar
  • 4,180
9 votes
2 answers
6k views

Remove screen from navigation stack in SwiftUI

I'm using NavigationLink to navigate screens in NavigationView. How can I remove screen from navigation stack? Not just hide the navigation "Back" button but completely remove screen from ...
badadin's user avatar
  • 547
9 votes
3 answers
3k views

Deep programmatic SwiftUI NavigationView navigation

I'm trying to get a deep nested programmatic navigation stack in order. The following code works as expected when navigation is done by hand (ie: pressing the links). When you press the Set Nav button ...
Andrew Lipscomb's user avatar
9 votes
1 answer
1k views

SwiftUI dismissing view by setting NavigationLink tag to nil

I'm trying to implement the logic of programmatic view pop in SwiftUI I set a tag on the items and create a corresponding variable for the selected item, but when I click the button on the DetaiView ...
Petr Tartynskikh's user avatar
8 votes
1 answer
5k views

How to remove opacity animation in SwiftUI NavigationLink

When tapping on a NavigationLink, it reduces the opacity slightly. Is there a way to disable this. I tried using .buttonStyle(PlainButtonStyle()) but that didn't have the desired effect. It is ...
santi.gs's user avatar
  • 604
8 votes
2 answers
7k views

How to put a condition to NavigationLink? SWIFTUI

I would like to put a condition to the NavigationLink. I have two variable, and the NavigationLink as below. @State var score = 0 @State var target = 10 NavigationLink(destination: level2()) {...
I Kaya's user avatar
  • 427
8 votes
3 answers
8k views

SwiftUI's NavigationLink `tag` and `selection` in NavigationView stops working if not all NavigationLinks are displayed

I have a list of items in a Form in a NavigationView, each having a detail-view that can be reached with NavigationLink. When I add a new element to the list, I want to show its detail-view. For that ...
Jannik Arndt's user avatar
8 votes
2 answers
4k views

SwiftUI NavigationView remove white space

I have a HomeView NavigationView { ZStack { VStack { NavigationLink(destination: ProfileView()) { if session.userInSession?.activated != 1 { ...
Gurmukh Singh's user avatar
8 votes
3 answers
5k views

SwiftUI override navigation bar appearance in detail view

I've got a super simple SwiftUI master-detail app: import SwiftUI struct ContentView: View { @State private var imageNames = [String]() var body: some View { NavigationView { ...
KerrM's user avatar
  • 5,161

1
2 3 4 5
23