frogcjn
frogcjn

Reputation: 838

Why View.onDisappear not get called?

In iOS 13 beta 4, all View.onDisappear do not get called.

There is a navigation view and push to a Detail View. When a user tap navigation back button, the DetailView.onDisappear not get called. How to fix it?

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: DetailView()) { Text("show") }
        }
    }
}

struct DetailView : View {
    var body: some View {
        Text("here")
            .onDisappear {
                print("onDisappear")
            }
    }
}

#if DEBUG
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

Upvotes: 2

Views: 1211

Answers (1)

Abhishek Maurya
Abhishek Maurya

Reputation: 765

In the current beta onAppear() works great but onDisappear() doesn’t seem to get called.

Upvotes: 6

Related Questions