Daniel
Daniel

Reputation: 11

How to hide item

I wanted to allow users to be able to hide their plans. In the code below, I wrote it, however, I can't change the label of the swipe. I would like to change delete to hide in the app, however, I could not find a way. So, I used the swipeActions, however, I am getting the error. Value of type 'ForEach<[Plan], Int, NavigationLink<Text, some View>>' has no member 'swipeActions'.

ForEach(plans_controller.plans) { plan in
                    
      NavigationLink(destination: planView()) {
          Text(plan.name)
      }
}.onDelete(perform: self.deleteRow)

Edit: Anyone who is having the problem, I used the following link to hide it. https://medium.com/swlh/how-to-delete-a-cell-by-clicking-a-button-in-swiftui-92c302d9c2e3

Upvotes: 0

Views: 111

Answers (1)

aheze
aheze

Reputation: 30516

Try putting .swipeActions inside the ForEach, not outside.

For example:

ForEach(plans_controller.plans) { plan in
    NavigationLink(destination: planView()) {
        Text(plan.name)
    }
    .swipeActions { ... }
}
.onDelete(perform: self.deleteRow)

... not:

ForEach(plans_controller.plans) { plan in
    NavigationLink(destination: planView()) {
        Text(plan.name)
    }
}
.onDelete(perform: self.deleteRow)
.swipeActions { ... }

Upvotes: 1

Related Questions