how can swiftui tabview detect a click on a tab?

As of iOS 14 you can use onChange to execute code when a state variable changes. You can replace your tap gesture with this:

.onChange(of: selectedTab) { newValue in
    model.myFunction(item: newValue)

If you don’t want to be restricted to iOS 14 you can find additional options here: How can I run an action when a state changes?

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top