And the working example, where the changes are the id given to the List, and the new Binding to the color:struct ContentView: View { @State private var arr: [Color] = [.red, .green, .blue] var body: some View { List { ForEach(Array(arr.enumerated()), id: .element) { (index, _) in ColorPicker( "Color", selection: Binding<Color>( get: { arr[index] }, set: { arr[index] = $0 } ) ) } .onDelete(perform: delete) } } private func delete(at offsets: IndexSet) { arr.remove(atOffsets: offsets) }} 这篇关于SwiftUI 从列表中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 04:11
查看更多