Hi Sydney,
Thank you very much for your reply!
I have updated my code as per your advice, but it seems that the rows are still able to be moved even when the Edit button is not clicked. Below is my updated code for your reference:
Thanks
Best,
Eugene
@AppStorage("fruits") private var fruits = Fruits.fruits
var body: some View {
NavigationStack {
VStack {
List($fruits, editActions: .move) { $fruit in
NavigationLink {
FruitView(title: fruit.title)
} label: {
fruit.icon
Text(fruit.title)
}
}
.environment(\.defaultMinListRowHeight, UIElementConstants.listCellHeight)
}
.toolbar { EditButton() }
.navigationTitle("Fruits")
}
}
Instead of the List constructor above, I have also tried the same one from your code snippet as shown below:
List($fruits, editActions: .move) { $fruit in
NavigationLink(fruit.title) {
FruitView(title: fruit.title)
}
}
The second code block from my original post is untouched.
Post
Replies
Boosts
Views
Activity
Hi, thank you very much for the solution!
Hi @darkpaw,
Thank you for helping. The moveItems is just a function as shown below.
private func moveItems(indices: IndexSet, newOffset: Int) {
self.items.move(fromOffsets: indices, toOffset: newOffset)
}
I've shown all the code but it doesn't work for me. But I think I've found the problem, all the views like CarView(), HouseView() have their own NavigationStack and I didn't pass in the NavigationPath binding.
Thanks
HI @Frameworks Engineer, thanks for pointing out. The reason for me doing so is to display the navigation title, but seems like it is wrong and unnecessary. All gud now, thanks!