UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Using Progress Bar

Forums > SwiftUI

  @State private var isLoading = false
  if isLoading {
                                ProgressView()
                            }

                            VStack {

                                ForEach(viewModel2.anuncios.sorted(by: ({ $1.timestampString < $0.timestampString }) ).filter({ "\($0)".contains(searchText) || searchText.isEmpty }) ) { anuncio in
                                    NavigationLink(destination: LazyView(ClassDetailView(anuncio:anuncio))) {
                                        ClassRowView(anuncio:anuncio)
                                    }

                                }
                            }

I want to show de progressview and when data is load, progressview desapper. How i can do it ?

2      

you need to pass into the structure the isLoading value. Where do you start the loading of whatever you are loading?

2      

Hi gfmolon

You need to change the var isLoading to get the data to show have done a small code to show

struct ContentView: View {
    @State private var isLoading = true

    var body: some View {
        Group {
            if isLoading {
                ProgressView()
            } else {
                // code to show data when loaded
                Text("Data loaded")
            }
        }
        .onAppear(perform: loadingCall)
    }

    func loadingCall() {
        // code to load data just using asyncAfter
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            isLoading = false // needed to change to show loaded data
        }
    }
}

3      

Thanks!

2      

One more thing... how can i do a RELOAD buton, to reload data with this progress bar, or use the gesture top to do it in a scrool view for exemple....

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.