0

My TabView looks like this:

var body: some View {
    TabView {
        TabView1()
            .tabItem() {
                Image("...")
                Text("...")
            }
            .onAppear { ??? }

        TabView2()
            .tabItem() {
                Image("...")
                Text("...")
            }
    }
    .onAppear { ??? }
}

When I enter the TabView, I'll be on TabView1. What I want to do is to load the content inside TabView2 when I'm on TabView1, so that the content in TabView2 is prepared when I click and switch to it.

I'm guessing that I need to do something in any of the .onAppear methods, but what exactly should I do? Thanks a lot!

  • Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and see: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). You will have to use your View Model to get that behavior. The views should not do that work. – Yrb Dec 09 '21 at 13:27
  • Could you please elaborate a little bit about what should I do in the View Model? I'm new to swift and I didn't have a view model for my views for now. Also, thanks for providing those link. – dodobird1210 Dec 09 '21 at 16:41
  • I would go through [Apple's SwiftUI Tutorials](https://developer.apple.com/tutorials/swiftui) & [Stanford's CS193P](https://cs193p.sites.stanford.edu) class. – Yrb Dec 09 '21 at 17:09

0 Answers0