This situation is no problem.enter link description here
So I'm confused, I don't know if this is a bug or whether Apple designed it this way.
struct HomePage: View {
var body: some View {
NavigationView {
VStack {
jumpView1
.padding()
.background(Color.red)
.padding()
jumpView2
.padding()
.background(Color.blue)
}
.navigationBarItems(leading:leftBarItem)
.navigationBarTitle("Home",displayMode: .inline)
}
}
var leftBarItem: some View {
NavigationLink(destination: CustomViewController()) {
Text("Go CustomViewController ")
}
}
var jumpView1: some View {
NavigationLink(destination: CustomViewController()) {
Text("Go CustomViewController")
.foregroundColor(.white)
}
}
var jumpView2: some View {
NavigationLink(destination: SecondPage()) {
Text("Go SecondPage")
.foregroundColor(.white)
}
}
}
struct FirstPage: View {
var body: some View {
NavigationLink(destination: CustomViewController()) {
Text("Go CustomViewController")
}
}
}
struct SecondPage: View {
var body: some View {
NavigationLink(destination: CustomViewController()) {
Text("Go CustomViewController")
}
}
}
the func dismantleUIViewController only call in leftBarItem Action, and never call, when push in body NavigatinLink
struct CustomViewController: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> CustomRealViewController {
let vc = CustomRealViewController()
return vc
}
func updateUIViewController(_ uiViewController: CustomRealViewController, context: Context) {
}
static func dismantleUIViewController(_ uiViewController: CustomRealViewController, coordinator: Coordinator) {
print("dismiss")
}
}
the func deinit only call in leftBarItem Action, and never call, when push in body NavigatinLink
class CustomRealViewController: UIViewController {
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
print("viewDidDisappear")
}
deinit {
print("deinit")
}
}