I have UIActivityIndicatorView that i want to start animate in viewdidload before i grab data from API and load into the table view . I then want to stop animating after loading . The problem is , it continues the animation and no data is shown forever . How can i start animating and stop the animation once data is loaded into the table view : This is my code below for the view did load and response method for getting data from api.
public enum indicatorColor {
static let color : UIColor = .white
}
override func viewDidLoad() {
super.viewDidLoad()
activityIndicator.color = indicatorColor.color
activityIndicator.startAnimating()
tableview.isHidden = true
tableview.separatorColor = .blue
tableview.delegate = self
tableview.dataSource = self
response()
}
func response () {
viewmodel.vmResponse(url: UrlPath.path.shared()) { [weak self](_) in
DispatchQueue.main.async {
self?.tableview.reloadData()
// self?.activityIndicator.stopAnimating()
// print(self?.viewmodel.articles)
}
}
}