ios - 同时更新两个 UILabel

标签 ios objective-c multithreading

我有两个 UILabel 需要以毫秒为单位进行更新。我运行我的应用程序并注意到其中一个 UILabel(“第二个 UILabel”)的更新速度比第一个慢。差别不大,但可以察觉。

第二个 UILabel 在将其结果显示在 UILabel 上之前进行了简短的计算。我怀疑我可能需要将其推送到后台线程。

我在 Java 中使用过线程,但想探索 GCD、操作队列、调度队列等。我已经阅读了很多关于它们的内容(尤其是从 Apple 网站),但就是无法理解它们。

所以我需要和这里的专家核实一下:

Q1:Second UILabel感知问题是否是因为更新UI Thread导致线程争用?

问题 2:我的应用程序更新第二个 UILabel 是否需要后台线程,或者 GCD 等是否足够?

最佳答案

答案。

dispatch_queue_t background_queue = dispatch_queue_create("label", NULL);

dispatch_async(background_queue, ^{
    // do some stuff that takes a long time here...

    // follow up with some stuff on the main queue
    dispatch_async(dispatch_get_main_queue(), ^{
        // Typically updating the UI on the main thread.

    });
});

关于ios - 同时更新两个 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23010539/

相关文章:

ios - UISplitViewController displayModeButtonItem 不显示

ios - UIButtons 在某些设备上不工作

iphone - 使用 CATransition 从右向左转换并返回?

c - 退出 pthread 会导致段错误

iphone - 将委托(delegate)从 ViewController 分离到自己的类

ios - 在键盘显示或隐藏时调整 UIView

ios - 如何在另一个 textField 的 alertView 之后将焦点转移到 Textfield

iphone - 如何在 didSelectRowAtIndexPath 中到达当前选定的单元格?

c++ - 双重检查单例线程安全的实现吗?

multithreading - eclipse RCP : Only one Job runs at a time?