I have something like this:
import SwiftUI
struct Overview: View {
@ObservedObject var firstArray = FirstArray()
var body: some View {
Group{
ScrollView(){
ForEach(self.firstArray.array, id: \.self){ array in
SubView(array: array)
}
Spacer()
}
}.navigationBarTitle("Overview")
}
}
struct SubView: View {
@State var array
var body: some View {
NavigationLink(destination: DetailInfo(array: array){
Image(systemName: "pencil.circle").resizable().frame(width: 30, height: 30)
}
}.navigationBarTitle("SubView")
}
struct DetailInfo: View {
@State var array
var body: some View {
List(){
ForEach(0..<self. array.count, id: \.self){item in
Text(item)
}.onDelete(perform: deleteItem)
}
}
func deleteItem(at offsets: IndexSet) {
self.array.remove(atOffsets: offsets)
}
}
When I delete an item in the DetailInfo it pops me back to the Overview. Why is that? Is that because of the ForEach "refreshing" in the Overview. How can I stay on the DetailInfo ? When leaving out the id: \.self in Overview it doesn't show this behaviour.