SwiftUI列表项装饰影响要删除的幻灯片
我有一个列表,其中包含以下项目:SwiftUI列表项装饰影响要删除的幻灯片,swift,swiftui,swiftui-list,Swift,Swiftui,Swiftui List,我有一个列表,其中包含以下项目: List { ForEach(filteredItems, id: \.self) { item in Text(item.termLowerCase) .font(fontItems) .foregroundColor(.white) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) .contentShape(Rectangle())
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))
)
此代码生成如下元素,包括选定元素的圆角
我的问题是,这种单元格装饰阻止了向左滑动单元格的删除工作
我该如何解决这个问题
您可能在错误的位置附加了
.onDelete
,它应该附加到ForEach
(不在行内)
ForEach(filteredItems,id:\.self){item in
文本(item.term小写)
}
onDelete先生{offsets in//I无法重现该问题,但我必须对其进行修改以使其能够编译。代码格式错误,缺少括号,并且您没有在视图顶部显示变量的声明方式。您是否提供完整的可重现示例以进行调试?您的回答在技术上是正确的,因为我发布的代码不正确。但我的问题超出了这个范围,在另一节课上。无论如何,谢谢。
ForEach(filteredItems, id: \.self) { item in
Text(item.termLowerCase)
}
.onDelete { offsets in // << here !!
print("deleting"
}