iOS:在 NSFetchResultsController 执行提取时呈现一个纺车

标签 ios nsfetchedresultscontroller

我正在使用 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/

相关文章:

swift - 使用 NSSortDescriptor 对一对多关系的 NSSet 类型的数据进行排序

cocoa-touch - 核心数据 : updating a managed object doesn't call the NSFetchedResultsControllerDelegate

Ios uialertcontroller uiimagepicker 忽略 : app crash

iphone - 日期字符串格式为 NSDate

ios - 在NSFetchedResultsController中标识数组的数组

ios - 在核心数据中使用搜索栏范围

swift - 第一个 TableView 部分标题不会滚动 Swift 4

ios - 选择提示音-快速

ios - 是否有 API 可以关闭 iPhone 上的 IP 流量?

ios - 如何在 Mac 上查看 Apple Watch 屏幕