I have this code to display a list of custom rows.
struct ContentView : View {
var body: some View {
VStack(alignment: .leading) {
List(1
While these answers are technically correct they will affect a List
or Form
globally(across the entire app) from my experience.
A hacky way I found to resolve this problem, at least in my app, is to add the following code to the "main" content view of the app:
.onAppear(perform: {
UITableView.appearance().separatorStyle = .none
})
Then on any other view that you want to the separator lines add this to the end of the List
or Form
view
.onAppear(perform: {
UITableView.appearance().separatorStyle = .singleLine
})
This seems to add the single line separator to any view sheet that is above the main content view. Again this is all anecdotal to my recent SwiftUI experience.
In my experience I only had to add the .onAppear(... = .singleLine)
method to one of my "detail" views and the separator line appeared on all subsequent views that were presented.
Edit: Another note as this answer continues to gain attention. This solution I posted doesn't solve all cases, it certainly did not solve it for me, again in some cases. I ended up using Introspect for SwiftUI to solve this problem across the entire app.
I hope this clears up some confusion and frustration as people come across this post.