I have a pretty simple view:
import SwiftUI
struct DataSceneSectionView: View {
@ObservedObject var model: DataSceneSectionModel
var body: some View {
ForEach(Array(model.entries.enumerated()), id: \.element) { (index, entry) in
NavigationLink(destination: DataSceneEntryView(model: entry.model)) {
Text(entry.title)
.tag(index)
}
}
}
}
where the model looks like this:
import Foundation
import SwiftUI
final class DataSceneSectionModel: ObservableObject {
@Published var entries: [DataSceneSectionEntry] = []
var dataTypeGroup: DataTypeGroup
init(dataTypeGroup: DataTypeGroup) {
self.dataTypeGroup = dataTypeGroup
self.entries = buildEntries()
}
private func buildEntries() -> [DataSceneSectionEntry] {
return DataType.allCases
.filter({
return $0.group == dataTypeGroup
})
.map({
return DataSceneSectionEntry(dataType: $0)
})
}
}
struct DataSceneSectionEntry: Identifiable, Hashable {
var id = UUID()
var dataType: DataType
var title: String { return dataType.localizedPlural }
var model: DataSceneEntryModel { return DataSceneEntryModel(dataType: dataType) }
}
Now, there is a strange effect: When tapping one of the entries, the linked view is shown correctly. After returning and tapping a different entry, the linked view for that one is shown correctly as well. BUT: When tapping the same entry as before, it is just highlighted, but no action is performed.
I suspected the missing tag
modifier, but this didn't change anything...
Any idea how this can be fixed?