Q:

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??

A:

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: https://stackoverflow.com/a/41529056/1370336
// Main thread by default: 
// show progress bar here.

DispatchQueue.global(qos: .background).async {
    // Background thread:
    // start loading your images here

    DispatchQueue.main.async {
        // Main thread, called after the previous code:
        // hide your progress bar here
    }
}

