通过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.
更多推荐
发布评论