Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 205
pigeon_39 Avatar asked Nov 29 '25 20:11

pigeon_39


2 Answers

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
    }
}
like image 147
Remy Cilia Avatar answered Dec 01 '25 11:12

Remy Cilia


Create Activity Indicator Programetically in your Second View Controller

    var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)

Add Below Code in viewDidLoad() of Second View Contoller

   activityIndicator.hidesWhenStopped = true
   activityIndicator.center = view.center
   activityIndicator.startAnimating() //For Start Activity Indicator

When Data is Filled in Table View Completely than Add below code for stoping Activity Indicator

   activityIndicator.stopAnimating() //For Stop Activity Indicator
like image 34
Sachin Dobariya Avatar answered Dec 01 '25 10:12

Sachin Dobariya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!