在从firebase实时数据库接收数据时,我没有找到任何显示UIActivityIndicator的内容。到目前为止,我已经使用过此代码,但它对我没用。
{% assign sorted_posts = site.categories[category] | sort: post.title %}
答案 0 :(得分:2)
您需要在firebase观察者回调范围外启动UIActivityIndicatorView动画,并在观察者返回快照后停止它。
var activityIndicator: UIActivityIndicatorView!
override func viewDidLoad() {
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle:
UIActivityIndicatorViewStyle.Gray)
activityIndicator.hidesWhenStopped = true;
activityIndicator.isHidden = true
activityIndicator.center = view.center;
addSubview(myActivityIndicator)
super.viewDidLoad()
}
func firebaseObserver() {
// Show indicator
activityIndicator.isHidden = false
activityIndicator.startAnimating()
// Firebase network observer
let connectedRef = Database.database().reference(withPath: ".info/connected")
connectedRef.observe(.value, with: { snapshot in
// Stop and hide indicator
self.activityIndicator.stopAnimating()
self.activityIndicator.isHidden = true
// Proceed with other operations.
})
}