大佬,我怎么才能在action中是知道删除哪个item啊?
zhouzhuhao opened this issue · 4 comments
zhouzhuhao commented
如题
fatbobman commented
在ForEach中定义button。其他类似数组、CorData可以使用id来确定需要删除的item
struct ContentView: View {
var body: some View {
ForEach(0..<100){ i in
let button1 = SwipeCellButton(
buttonStyle: .titleAndImage,
title: "Delete",
systemImage: "trash",
titleColor: .white,
imageColor: .white,
view: nil,
backgroundColor: .green,
action: {
print("should delete \(i)")
},
feedback: true
)
let slot1 = SwipeCellSlot(slots: [button1])
Text("id:\(i)")
.frame(height:100)
.swipeCell(cellPosition: .left, leftSlot: slot1, rightSlot: nil)
}
}
}
zhouzhuhao commented
在ForEach中定义button。其他类似数组、CorData可以使用id来确定需要删除的item
struct ContentView: View { var body: some View { ForEach(0..<100){ i in let button1 = SwipeCellButton( buttonStyle: .titleAndImage, title: "Delete", systemImage: "trash", titleColor: .white, imageColor: .white, view: nil, backgroundColor: .green, action: { print("should delete \(i)") }, feedback: true ) let slot1 = SwipeCellSlot(slots: [button1]) Text("id:\(i)") .frame(height:100) .swipeCell(cellPosition: .left, leftSlot: slot1, rightSlot: nil) } } }
谢谢大佬,我去试一下
zhouzhuhao commented
iOS13不支持??
fatbobman commented
是的。使用了SwiftUI2.0的部分特性。需要iOS14
ReadMe里有说明