0

Hello I am trying to simply add a swipe action to a list of subviews In the parent view. Each subview is its own navigation link and putting the swipe action is not working. How can I fix this. I don't get any errors though in the code.

struct Tip: Identifiable, Codable, Hashable{
    var id: String
    var caption: String
    var link: String
}
                    ForEach(viewModel.ThreeTips) { tip in
                        TipRowView(tip: tip)
                            .swipeActions {
                                Button {
                                    
                                } label: {
                                    Text("delete")
                                }
                            }
                            .tint(.red)
                    }

1 Answer 1

1

I believe swipeActions is meant for List (and it works there):

List(viewModel.ThreeTips, id: \.self) { tip in
  TipRowView(tip: tip)
    .swipeActions {
      Button {                                    
      } label: {
        Text("delete")
      }
    }
    .tint(.red)                
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, that works. Is there no way to use the forEach. When I use the list it puts the elements in a weird view and adds padding to each side
List has the listStyle(_:) modifier: developer.apple.com/documentation/swiftui/view/liststyle(_:) Applying one of the pre-defined styles should resolve the issue. Perhaps, PlainListStyle will work: developer.apple.com/documentation/swiftui/plainliststyle. Here's the discussion on SO: stackoverflow.com/questions/56614080/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.