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: 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
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With