更新使 UI 变慢

Updating makes the UI slow

UIPageViewController 的每个页面包含 6 个视图,每个视图包含一个 ProgressBar 以在后台显示下载进度运行。

每次,下载进度都会在 0.01 秒内更新 UI 大约 1%(我猜是这样)。因为我们有 6 个视图,所以每个页面上 UI 的更新太多,当你想导航到另一个页面时 UI 会很慢。

我正在使用 NSURLSession 和 NSURLSessionDownloadTask 下载文件,然后在主线程上更新 UI:


//- on main thread
dispatch_async(dispatch_get_main_queue(), ^{

    //- update UI
    ...
}

以下是我每次更新的记录,包括时间。

...
2015-08-25 14:42:42.524 MyApp[896:230684] Feedback = On Downloading ...
2015-08-25 14:42:42.543 MyApp[896:230684] Feedback = On Downloading ...
2015-08-25 14:42:42.567 MyApp[896:230683] Feedback = On Downloading ...
2015-08-25 14:42:42.590 MyApp[896:230753] Feedback = On Downloading ...
...
2015-08-25 14:42:44.134 MyApp[896:230753] Feedback = On Unzipping ...
2015-08-25 14:42:44.139 MyApp[896:230753] Feedback = On Unzipping ...
2015-08-25 14:42:44.149 MyApp[896:230753] Feedback = On Unzipping ...
2015-08-25 14:42:44.159 MyApp[896:230753] Feedback = On Unzipping ...
...
2015-08-25 14:42:45.962 MyApp[896:230753] Feedback = On Parsing ...
2015-08-25 14:42:45.964 MyApp[896:230753] Feedback = On Parsing ...
2015-08-25 14:42:45.966 MyApp[896:230753] Feedback = On Parsing ...
...
2015-08-25 14:42:46.071 MyApp[896:230753] Feedback = Finish Parsing Tags XML file
2015-08-25 14:42:46.072 MyApp[896:230753] Feedback = Parse Tags XML file successfully
2015-08-25 14:42:46.072 MyApp[896:230753] Feedback = Handle Package Successfully

有没有办法让它更快?

谢谢,

注意:我正在开发 iPad 应用程序,XCode7、ios9、objective-C

如果您确定是进度更新给您带来了麻烦,您可以只更新一个代表进度量的数字——在后台——然后设置一个计时器来读取数字和在前台执行 UI 更新。

用户需要多久查看一次更改? ……半秒? ...一秒钟?

NSURLSession 确实 "chatty" 超出了必要。)