Learn Courses My Dashboard

Question about TabView

The issue is TabView will work fine when switching between tab. But When I click the images(contain NavigationLink) from HomeView to go to BreakfastView, the view will not go back to HomeView by tapping the Home tab and it will only stuck on BreakfastView.

I put my code to GitHub.
Thank you for everyone who try to asking my question.

But it works from the other tabs back to homeview?

Worked fine for me, after I made some minor adjustments to account for the fact that I don’t have all your assets or Views.

Like roosterboy says, it works for me too after having to create the other Views in order to select the individual tabs. Having said that, we don’t have the benefit of having your HomeView content that you are working with so have no idea what is going on in that View that may be affecting the operation of the Tabs.

It’s very difficult to advise what you need to change when we do not have access to the entire project. If you are prepared to share the project with one of us then we may be able to offer a solution.

An option is to compress the entire project into an archive (zip file) and post it to either DropBox or Google Drive and share a link here.
The other option is to share the link via a private message to myself if you prefer not to make the project widely available.

oh so why even put tabs when you have “navigation” in the form of clicking the buttons… i think it gets confused since the “tab” number is different and you basically forcefully changed to a different view using the buttons, which is probably why it doesn’t detect the changing of view…

did you present the views when doing the button navigation? it might be better to change “centerX” instead so it changes tabs naturally

Couple problems here:

  1. Clicking the Home button when Home is already selected does nothing because the value of selected does not change. SwiftUI is smart enough to not change any state if the new value is the same as the old value. Prevents unnecessary renderings.
  2. You are expecting a navigation stack to pop to root when you switch tabs or even just click again on the active tab. You have to code that behavior explicitly because it won’t happen automatically.

Thank you. I write a code to make it work.