Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIActivityIndicatorView(微调器)在加载远程json数据后不会显示或停止_Json_Swift_Core Data - Fatal编程技术网

UIActivityIndicatorView(微调器)在加载远程json数据后不会显示或停止

UIActivityIndicatorView(微调器)在加载远程json数据后不会显示或停止,json,swift,core-data,Json,Swift,Core Data,我正在开发一个包含核心数据的应用程序,在预加载本地数据后,它将从S3URL加载json数据。因此,我想显示微调器,因为出于某种原因,在(空白冻结表视图)中显示数据平均需要8秒,因此我需要显示一个灰色微调器(活动指示器),并在数据加载完成时正确停止它。 远程数据将在之前预设的秒数(我将其设置为4小时,以避免在研讨会期间创建如此多的请求)开始与服务器同步,并在AppDelegate的ApplicationIDBecomeActive中释放服务器负载 问题是,当数据被加载/停止指示器显示数据行时,我正

我正在开发一个包含核心数据的应用程序,在预加载本地数据后,它将从S3URL加载json数据。因此,我想显示微调器,因为出于某种原因,在(空白冻结表视图)中显示数据平均需要8秒,因此我需要显示一个灰色微调器(活动指示器),并在数据加载完成时正确停止它。 远程数据将在之前预设的秒数(我将其设置为4小时,以避免在研讨会期间创建如此多的请求)开始与服务器同步,并在AppDelegate的ApplicationIDBecomeActive中释放服务器负载

问题是,当数据被加载/停止指示器显示数据行时,我正在体验旋转器的问题,因此空白TabLVIEW仍然阻塞UI。

案例1)微调器在viewDidLoad中启动,在controllerDidChangeContent中停止(在主线程中)。结果:我看不到微调器,似乎数据仍在加载,所以它显示没有微调器的空白tableview-在这种情况下,或者速度太快,或者controllerDidChangeContent在加载数据之前完成

案例2)微调器在VIEWWILLISAPEAR中启动,在viewWillDissapear中停止。它在正确的时间在正确的屏幕上显示旋转视图,但仅在用户更改视图时停止

案例3)然后我尝试使用标志。例如,isLoading等于true,并将其设置为false以停止微调器

#AppDelegate
func updateSeedJsonFromServer(){
让task=NSURLSession.sharedSession().dataTaskWithURL(NSURL(字符串:seedLoadURL)!,completionHandler:{(数据、响应、错误)->中的Void
变量错误:n错误?=nil
让jsonArray=NSJSONSerialization.JSONObjectWithData(data!,选项:nil,error:&error)作为!NSArray
让entity=NSEntityDescription.entityForName(“EventModel”,inManagedObjectContext:self.managedObjectContext!)
对于jsonArray中的JSONDICTIONAL{
让eventSectionDate=jsonDictionary[“eventSectionDate”]作为!字符串
让priority=jsonDictionary[“priority”]作为!NSNumber
让room=jsonDictionary[“room”]作为!字符串
让sessionDate=jsonDictionary[“sessionDate”]作为!字符串
让desc=jsonDictionary[“desc”]作为!字符串
让sessionTitle=jsonDictionary[“sessionTitle”]作为!字符串
让speaker=jsonDictionary[“speaker”]作为!字符串
让breakDate=jsonDictionary[“breakDate”]作为!字符串
让isFavorite=jsonDictionary[“isFavorite”]作为!Bool
让newEvent=EventModel(实体:实体!,
insertIntoManagedObjectContext:self.managedObjectContext)
newEvent.eventSectionDate=eventSectionDate
newEvent.priority=优先级
newEvent.room=房间
newEvent.sessionDate=sessionDate
newEvent.desc=desc
newEvent.sessionTitle=sessionTitle
newEvent.speaker=演讲者
newEvent.breakDate=breakDate
newEvent.isFavorite=NSNumber(bool:isFavorite)
}
self.managedObjectContext?.save(&错误)
println(“从服务器导入\(jsonArray.count)事件…”)
//继续并设置lastServerCheck值
//停止旋转?
NSUserDefaults.standardUserDefaults().setObject(NSDate(),forKey:“lastServerCheck”)
NSUserDefaults.standardUserDefaults().synchronize()
})
task.resume()
}
/////
func ApplicationIDBecMeactive(应用程序:UIApplication){
//当应用程序处于活动状态时,如果不是很快,则启动服务器的后台刷新
设tooSoonSeconds:NSTimeInterval=60*240//4h
如果endOfTimeDate.compare(NSDate())==NSComparisonResult.OrderedDescending{
将lastServerCheck=NSUserDefaults.standardUserDefaults().valueForKey(“lastServerCheck”)设为?NSDate??BeginingOfftimeDate
如果NSDate().timeIntervalSinceDate(lastServerCheck)>ToosonSeconds{
让fetchserverRequest=NSFetchRequest(entityName:“EventModel”)
变量错误:n错误?=nil
让结果=managedObjectContext?.countForFetchRequest(fetchserverRequest,错误:&error)
如果(结果!=零){
如果let results=managedObjectContext?.executeFetchRequest(fetchserverRequest,错误:&error){
对于结果中的obj{
设e=obj为!EventModel
managedObjectContext?.deleteObject(e)
}
}
managedObjectContext?.save(&错误)
}
//dispatch\u async(dispatch\u get\u main\u queue(){
self.updateSeedJsonFromServer()
println(“启动updateFromServer…”)
//                    })
}否则{
//目前未与服务器进行检查-
println(“当前未在\(NSDate())检查服务器;上次检查是\(lastServerCheck)”)
}
}否则{
//关断开关-
println(“不再使用aws服务器检查-关闭开关打开”)
}

}
使用完成处理程序显示和隐藏微调器:

func updateSeedJsonFromServer() {

self.startSpinner()
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string:seedLoadURL)!, completionHandler: { (data, response, error) -> Void in
//on the first line
self.stopSpinner()

}).resume()            
而不是我们