2016-09-16 45 views
0

从我在Swift 2.0中的iOS应用程序中,在后台线程中请求来自服务器的数据时,显示自定义微调器注释。 一旦我得到数据并更新sqlite数据库(约15秒处理所有查询),微调开始冻结。在XCode中,设备cpu显示95%和100%之间的活动。 我试图以不同方式使用GRAND CENTRAL DISPATCH,但我没有找到如何在不冻结微调器动画的情况下使其工作。 任何想法如何解决这个问题? 谢谢!处理后台线程时iOS UI微调框冻结

我不能张贴整个代码,但它是与此类似:

//Using the spinner here https://github.com/icanzilb/SwiftSpinner 

Spinner.show("Please wait", animated: true) 

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) 
{ 

    //around 5 seconds to get data 
    var data = getDataFromServer() 

    //around 20 sec to process and save the data in sqlite. It stops spinning from here.. 
    saveDataInDB(data) 

} 
+1

你可以请你发布你的代码吗? – anhtu

+0

你可以显示'saveDataInDB'的功能吗?听起来好像它可能在主线程上做了一些繁重的处理。 – Kamchatka

+0

我更新了问题并根据要求添加了一些代码。 – Philiz

回答

0

我发现的bug。在saveDataInDB()中,我使用OAuthSwift进行请求,在接收回调时更改执行线程。它在主线程上跳回,然后在主线程上运行db查询。我在这里为这个问题开了一个新的问题:OAuthSwift request callback on main thread