我正在使用 NSFetchedResultsController
来填充 UITableView
。提取需要一些时间,因此我想在提取过程中向用户展示一个纺车。
我该怎么做?
最佳答案
您应该在主线程中启动微调器,并将“繁重的工作”推送给辅助线程。工作完成后,停止微调器。你可以用这样的东西来实现:
// Start the spinning here.
[mySpinner startAnimating];
// Declare the queue
dispatch_queue_t workingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// it's not, so we will start a background process to calculate it and not block the UI
dispatch_async(workingQueue,
^{
// Some heavy work here.
dispatch_async(dispatch_get_main_queue(), ^{
// stop the spinner here
[mySpinner stopAnimating];
});
});
在主线程中执行以下操作不会让您完成您想要的:
Start Spinner => Heavy work => Stop Spinner
当 Heavy 工作开始时,它会阻塞您的 UI 线程,因此您不会真正看到 UIActivityMonitor
动画。
最后,我建议您使用 this作为微调器。
关于iOS:在 NSFetchResultsController 执行提取时呈现一个纺车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10531233/