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.
1,127
questions
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 ...
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 ...
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("...
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 ...
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: &...
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 ...
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{
...
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.
...
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 ...
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 ...
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?
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(...
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 ....
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 ...
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 ...
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 ...
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 ...
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 ...
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: ...
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 ...
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 : ...
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 ...
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")
}
...
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/...
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 {
...
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 ...
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.
...
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 ...
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 ...
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 ...
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) ...
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 ...
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 ...
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 {
...
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)
...
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 ...
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 ...
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 ...
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: ...
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....
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 ...
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 {
...
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 ...
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 ...
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 ...
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 ...
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()) {...
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 ...
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 {
...
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 {
...