我有一个包含以下项目的列表:
List {
ForEach(filteredItems, id: \.self) { item in
Text(item.termLowerCase)
.font(fontItems)
.foregroundColor(.white)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.contentShape(Rectangle())
.onTapGesture {
// doSomething()
}
.onDelete { offsets in
print("deleting"
}
.listRowBackground(
Group {
if item == selectedItem {
Color("selectedColor").mask(RoundedRectangle(cornerRadius: 20))
} else {
Color.clear
}
}
.padding(EdgeInsets(top: 0, leading: 5, bottom: 0, trailing: 5))
)
此代码会生成以下元素,包括所选元素的圆角。
我的问题是,这种单元格装饰会阻止滑动单元向左删除以进行工作
我该如何解决?
答案 0 :(得分:1)
您可能在错误的位置附加了.onDelete
,应该附加在ForEach
上(不在行内)
ForEach(filteredItems, id: \.self) { item in
Text(item.termLowerCase)
}
.onDelete { offsets in // << here !!
print("deleting"
}