简体   繁体   中英

SwiftUI: Execute code when back button for NavigationView is pressed

I have MainView, which has a navigationLink to EditProfileView.

When I press the back button on EditProfileView, I want some code to execute that updates a database.

I would use onDisappear(), but the issue is that EditProfileView has another view ImagePickerView presented as a sheet come up, and having that view come up triggers onDisappear().

In other words, I want my database code to execute only when we press the back button to go from EditProfileView back to MainView.

Is there a way to do this?

Add your own back button to replace the native one as the left button. Then programmatically dismiss your view.

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