我有触发活动指示符的代码:
activityIndicator.startAnimating()
一旦触发,我会继续启动一些后台任务(例如,转到服务器,获取数据,完成后回调)。
我遇到的问题是,活动指示器的行为在某种意义上是不一致的,即从UI上显示它有时可见/得到渲染和动画,有时不会(特别是如果应用程序在后台并返回到前台) )
我不确定在继续启动后台任务之前,当我调用startAnimating()
时,我需要做些什么来确保它始终在屏幕上呈现。
非常感谢任何指导。
感谢。
答案 0 :(得分:1)
我认为这是因为您可能在主线程之外使用UI。尝试在
中包装代码dispatch_async(dispatch_get_main_queue(), ^{
// Your code to run on the main queue/thread
self.activityIndicator.startAnimating()
});