同时更新两个UILabel

时间:2014-04-11 10:50:50

标签: ios objective-c multithreading

我有两个需要在毫秒级更新的UILabel。我运行我的应用程序并注意到其中一个UILabel("第二个UILabel")的更新速度比第一个慢。它并没有太大差异,但可以感知到。

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

我在Java中使用过线程,但是想要探索GCD,操作队列,调度队列等等。我已经对它们进行了大量阅读(尤其是来自Apple网站),但是我们无法理解它们。

所以我需要在这里与大师核实:

Q1:由于更新导致线程争用的UI线程导致第二个UILabel感知问题?

Q2:我的应用更新第二个UILabel需要后台线程还是GCD等?

1 个答案:

答案 0 :(得分:1)

答案。

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.

    });
});
相关问题