一组中的一个UILabel不会更新文本(One UILabel in a set of three won't update text)

编程入门 行业动态 更新时间:2024-10-28 20:23:19
组中的一个UILabel不会更新文本(One UILabel in a set of three won't update text)

通过GET url请求将一些数据返回给我后,我有三个UILabel正在更新。 前两个标签在获取数据后更新其文本,第三个标签不会更新文本,直到我点击标签。 我已经检查过,并且我的所有标签都在UIKit要求的主线程上更新,但是我无法弄清为什么三个标签中的任何一个都以相同的方式设置,并未按预期进行更新。

I have three UILabel's I'm updating after some data is returned to me through a GET url request. The first two label's update their text fine upon obtaining the data, the third label won't update its text until I tap on the label. I have already checked and all of my labels are being updated on the main thread as UIKit demands, but I can't figure out why one of three labels, all set up the same way, is not updating itself as expected.

最满意答案

事实证明,当UILabel没有明确的宽度,并且其文本被设置为“”时,标签有效地获得0宽度,然后在文本被编辑时不重新展开。 给我的标签定义宽度解决了问题。 另外两个标签没有问题,因为它们的值从来不是“”,而是0.0,所以它们总是有一些文本。

As it turns out, when a UILabel doesn't have an explicit width, and its text gets set to "", the label effectively gets 0 width and then doesn't reexpand when the text gets edited. Giving my label a defined width fixed the problem. The other two labels weren't having a problem because their values were never "", but were 0.0 instead so they always had some text in them.

更多推荐

本文发布于:2023-08-06 20:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组中   文本   UILabel   text   set

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!