This code works well in iPhone but not on iPad. In iPad, although the "Selected topic" text in TopicDetailView changes with every list selection, **onAppear is NOT getting called every single time. **
I need to do some backend operation on onAppear here. What am I doing wrong here? At first it looks like working fine, but go backward tapping in list, random tapping, every time, "selected topic " changes, but NOT every time onAppear gets called. I must have the onAppear called every time to run backend operations. I have latest devices, simulators, Xcode as of today. I cannot use NavigationStack as I need to support ios15.0 onwards
import SwiftUI
struct TopicsView: View {
var topics = ["Topic1","Topic2","Topic3"]
var body: some View {
NavigationView {
List(topics, id:\.self ) { topic in
NavigationLink(
destination: TopicDetailView(topic: topic).id(UUID())
) {
Text(topic)
}
}
}
}
}
struct TopicDetailView: View {
var topic: String
var body: some View //body{
{
VStack{
Text("Selected topic \(topic)")
}
.onAppear(){
print("on appear on topic \(topic)")
}
.onChange(of: topic){ v in
print("on change to topic \(v)")
}
}
}
struct ContentView: View {
var body: some View {
TopicsView()
}
}