When making a List with a row that pushes to a new view, SwiftUI adds a disclosure indicator ">" automatically? How do I remove it if I don't want it?
NavigationView {
List {
NavigationButton(destination: DetailView()) {
ListItem()
}
}
.navigationBarTitle(Text("Some title"))
}
On a UITableViewCell you set Accessory to None but how do I do that in SwiftUI?
NavigationLink
is what we should define in a scope enclosed inside aNavigationView
. But when we useNavigationLink
it is attached to the enclosing view, so to reuse the sameNavigationLink
with other views, we usetag
which differentiates between different Destinations.Here we bind a
Hashable
property with all theNavigationLinks
present in ourVStack
so that when a particular View is tapped we can notify which Destination should be opened by setting the value ofBindable
property. If we don't notify the correct Destination by setting the value oftag
, always the View defined inside the Closure ofNavigationLink
will be clickable and nothing else.Using this approach you don't need to wrap all your clickable views inside
NavigationView
, any action on any view can use anyNavigationLink
just by setting thetag
.Thanks, hope this helps.
This helps to push and pass the model to the next navigation view controller.
Removing
List
and just usingForEach
works fine with navigation link. You just have to create your own list row. This works for meAs of beta 6, this works well:
just came here looking for the answer to this question, but none of the proposed solutions worked for me (can't have an empty view, because i want to put something in the list row; i'm already messing with the padding (and increasing trailing padding didn't seem to work) ... i was about to give up, and then something occurred to me: what if you crank up the z-index of the list row itself? seemed somewhat unlikely, but i gave it a try and, i'll be damned, it worked! i was so pleasantly surprised, i felt like sharing ...
e.g.:
Swift 5, Xcode 11. ZStack works perfect.