1. Navigate from the main page to the sub page, the sub page dynamically reads an array, and ForEach renders a list. 2. At the moment of opening the sub page, try to close the page by right sliding to close, but cancel the operation after sliding a little. 3. Slide right again to close the sub page. At this time, the navigation bar of the sub page appears on the main page, generating ghosts. 4. In the process of reproduction, slide left and cancel before rendering the list, or slide left and cancel after rendering the list, this problem will not occur
import SwiftUI struct ContentView: View { var body: some View { NavigationView{ NavigationLink( destination: SubView(), label: { Text ("Go to the next page") }) .navigationBarTitle(Text("Main View"), displayMode: .inline) } } } struct SubView:View { @State var message: String= @State var list: [String] = [] var body: some View{ VStack{ Text(message) ForEach(0..<list.count){ index in Text(list[index]) } } .onAppear(){ DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) { Self. message="The operation is successful, please slide left to return to the previous page" self.list = [ "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", ] } } .navigationBarTitle(Text("Sub View"), displayMode: .inline) .navigationBarItems( trailing: Button(action: { self.message = "Right tapped! " }, label: { Text("Right") })) } }