How to show activity indicator while tableView loads?

前端 未结 12 1570
说谎
说谎 2021-01-30 21:44

When I switch between my tabs it loads some seconds and I want to know that my data is loading. For that I decided to add an activity indicator.

I wrote a little functio

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 22:07

    SWIFT

    Place this below your class:

    let indicator:UIActivityIndicatorView = UIActivityIndicatorView  (activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
    

    Place this in your loadView():

    indicator.color = UIColor .magentaColor()
    indicator.frame = CGRectMake(0.0, 0.0, 10.0, 10.0)
    indicator.center = self.view.center
    self.view.addSubview(indicator)
    indicator.bringSubviewToFront(self.view)
    indicator.startAnimating()
    

    In my case, I am requesting json objects through a func request, so I placed this at the end of that function to remove the activity indicator once the data loads:

    self.indicator.stopAnimating()
    self.indicator.hidesWhenStopped = true
    

提交回复
热议问题