简体   繁体   中英

Can I add some action when I push the Navigation back button in SwiftUI?

I'm developing my first ios App.

I'm using Xcode 11.3 and Swift5

I'm not sure it is possible, can I add an action when I push the back button in NavigationLink?

(In this picture, the back button is 'Bibles' button.)

NavigationLink(destination: VerseList(bible: self.bible, chapter: c.chapter)){
               ChapterRow(chapter: c.chapter)
            }.navigationBarTitle("Chapters")

This is my code. and I want to add 'action'..

Is there any better way to do that?

I think it would be more likely be like this.

NavigationLink(destination:VerseList(bible: self.bible, chapter: c.chapter)
                   .onDisappear {
                       // put action here
                   }
              ){ChapterRow(chapter: c.chapter)}
.navigationBarTitle("Chapters")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM