ALL BUSINESS
COMIDA
DIRECTORIES
EDUCATIONAL
ENTERTAINMENT
FASHION TIPS
FINER THINGS
FREE CREATOR TOOLS
HEALTH
MARKETPLACE
MEMBER's ONLY
MONEY MATTER$
MOTIVATIONAL
NEWS & WEATHER
TECHNOLOGIA
TELEVISION NETWORKS
USA VOTES 2024
VIDEOS
INVESTOR RELATIONS
IN DEVELOPMENT
Posted by - Latinos MediaSyndication -
on - Mar 28 -
Filed in - Technology -
-
280 Views - 0 Comments - 0 Likes - 0 Reviews
How can I enable multi-select and then move / reorder selected items in a List with ForEach (in SwiftUI)?
I tried the following code. On Mac it works fine - it allows me to select multiple items, and then drag them all together to another place in the list. On iOS it allows me to move individual items with drag-and-drop, and allows me to enter Edit mode to select multiple items but when I try to move the selected items with drag-and-drop, they can be dragged but they can't be dropped elsewhere in the list:
struct ExampleListView: View { @State var items = ["Dave", "Tom", "Jeremy", "Luke", "Phil"] @State var selectedItems: Set<String> = .init() var body: some View { NavigationView { List(selection: $selectedItems) { ForEach(items, id: \.self) { item in Text(item).tag(item) }.onMove(perform: move) } .navigationBarItems(trailing: EditButton()) } } func move(from source: IndexSet, to destination: Int) { items.move(fromOffsets: source, toOffset: destination) } }
Edit - This code has the same behavior:
struct ExampleListView: View { @State var items = ["Dave", "Tom", "Jeremy", "Luke", "Phil"] @State var selectedItems: Set<String> = .init() var body: some View { NavigationView { List($items, id: \.self, editActions: .all, selection: $selectedItems) { $item in Text(item).tag(item) } .navigationBarItems(trailing: EditButton()) } } func move(from source: IndexSet, to destination: Int) { items.move(fromOffsets: source, toOffset: destination) } }