0

My codes are like the following: When swipe a list item left, a red "delete" button will appear, and when click the item, it will show a sheet. Now I hope it can display two buttons, "delete" and "edit", when I click the "edit" button the sheet shows. How to do it?

List{
            Text("unit:\(care.unit!)")

            ForEach(care.sortedMarks,id:\.self){ m in


                Button(action: {
                    self.showSheet.toggle()
                    self.mark = m

                }){
                    VStack(alignment:.leading){
                        HStack{
                            Text(self.formatDate(dateIntervalSince1970: m.dateIntervalSince1970))
                            Spacer()
                            Text(String(format:"%.2f", m.value))
                        }
                        Text(m.memo ?? "")
                    }
                }
            }
            .onDelete(perform: deleteMarks)



        }
龙方哲
  • 125
  • 1
  • 9
  • Hi, what do you want to edit? onDelete is an action of ForEach, not of List. – MacUserT May 25 '20 at 14:56
  • I want ForEach items display delete and edit button when a item swipe left. Add onDelete modifier will add the delete button, but how to add the edit button – 龙方哲 May 26 '20 at 09:47
  • Please, read [this post](https://stackoverflow.com/questions/57112426/swiftui-custom-swipe-actions-in-list). I think the answer to this post will help you with your problem too. – MacUserT May 27 '20 at 15:25

0 Answers0