gpt4 book ai didi

ios - 同时更新两个 UILabel

转载 作者:行者123 更新时间:2023-11-29 12:48:38 25 4
gpt4 key购买 nike

我有两个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com