user16098302
user16098302

Reputation:

why list view items become gray after click the list items in SwiftUI?

I have list items in SwiftUI and when I click the list items it stay in gray color when I back to list view menu. Is there any solution?

DarkMenuView:

struct DarkMenuView: View {
    @AppStorage("isDarkMode") private var isDarkMode = false
    
    var body: some View {
        VStack{
            Picker("Mode" , selection: $isDarkMode) {
                Text("Light")
                    .tag(false)
                
                Text("Dark")
                    .tag(true)
            }.pickerStyle(SegmentedPickerStyle())
            .padding()
            List(0..<5, id: \.self) { num in
                NavigationLink(destination: Text("\(num)")) {
                Text("\(num)")
                    
                }
                    
            }
        }.navigationTitle("Dark Menu")
        .onAppear() {
                    print("DarkMenuView.onAppear()")
                }
    }
}

screenshot:

enter image description here

Upvotes: 2

Views: 601

Answers (2)

Imran Rasheed
Imran Rasheed

Reputation: 956

You can achieve this by making selection style None

.onAppear {
    UITableViewCell.appearance().selectionStyle = .none
}

Upvotes: 0

Works well in ios-15. You could try adding ".isDetailLink(false)" to the NavigationLinks.

Upvotes: 1

Related Questions