Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI NavigationButton without the disclosure indicator?

Tags:

swiftui

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?

like image 897
Radde Mojsovski Avatar asked Jun 09 '19 16:06

Radde Mojsovski


People also ask

How to hide disclosure indicator SwiftUI?

For the navigation link, instead of presenting the Text view, we change it to display an empty view. And, we attach the opacity modifier to NavigationLink and set its value to 0 . If you test the change in the preview, the disclosure indicator should disappear.

How does NavigationLink work SwiftUI?

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. In practical terms, this means we can programmatically trigger the activation of a navigation link by setting whatever state it's watching to true.

How do I create a list in SwiftUI?

Probably the simplest way to build a list is to create a new SwiftUI view and wrap the Hello World text in a List: struct StaticListView: View { var body: some View { List { Text("Hello, world!") } } } To add more items to the list, we can just add another line: List { Text("Hello, world!") Text("Hello, SwiftUI!") }


2 Answers

Setting the NavigationLink width and hiding it did the trick for me

List {   ForEach(pages) { page in     HStack(spacing: 0) {       Text("Something")        NavigationLink(destination: Text("Somewhere")) {         EmptyView()       }       .frame(width: 0)       .opacity(0)     }   } } 
like image 133
Manny Avatar answered Oct 04 '22 20:10

Manny


Swift 5, Xcode 11. ZStack works perfect.

var body: some View {     NavigationView {         List {             ForEach(viewModel.currenciesViewModel) { cellViewModel in                 ZStack {                     cellViewModel.makeView()                     NavigationLink(destination: ChooseCurrencyListView()) {                         EmptyView()                     }                     .buttonStyle(PlainButtonStyle())                 }             }         }         .navigationBarHidden(true)         .navigationBarTitle("", displayMode: .inline)     } } 
like image 25
Mike Glukhov Avatar answered Oct 04 '22 20:10

Mike Glukhov