Activity indicator until load the next view

In my firstViewController there is a UIButton (GalleryButton) and in my secondViewController there is a UITableView. When user taps the GalleryButton it takes 2-3 seconds time to open the secondViewController and load the images. I want to show an UIActivityIndicator until load the secondViewController. How to do so??


  • You should load the images in a background thread and display the UIActivityIndicator in the main thread. I already replied to a similar issue here:

    // Main thread by default: 
    // show progress bar here. .background).async {
        // Background thread:
        // start loading your images here
        DispatchQueue.main.async {
            // Main thread, called after the previous code:
            // hide your progress bar here