Daniel Seo
Daniel Seo

Reputation: 37

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?

Upvotes: 0

Views: 404

Answers (1)

Marc T.
Marc T.

Reputation: 5320

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")

Upvotes: 1

Related Questions