UILabels 在第一次加载视图时不会更新。
我有 UITableview
根据所选行设置另一个视图的 UILabel
。
在第一次选择任何行时,视图会加载空标签(未设置任何内容),一旦我向后导航,然后当我选择之后的一行时,它就会完美加载。
为什么不在第一个选择上设置标签?
我有以下代码:
NSLog(@"object at index 0 is %@", [tempArray2 objectAtIndex:0]);
self.categoryQuoteViewController.aLabel.text = [tempArray2 objectAtIndex:0];
self.categoryQuoteViewController.bLabel.text = [tempArray2 objectAtIndex:1];
NSLog(@"the first label is %@",self.categoryQuoteViewController.aLabel.text);
第一个 NSLog
打印该值,然后在设置它并打印标签的值后,它是 null
。
I have UITableview
s that set another view's UILabel
s depending on the row selected.
On the first selection of any row, the view loads with empty labels (nothing set), as soon as I navigate back and then when I choose a row after that it loads perfectly.
Why aren't the labels being set on the first selection?
I have the following code:
NSLog(@"object at index 0 is %@", [tempArray2 objectAtIndex:0]);
self.categoryQuoteViewController.aLabel.text = [tempArray2 objectAtIndex:0];
self.categoryQuoteViewController.bLabel.text = [tempArray2 objectAtIndex:1];
NSLog(@"the first label is %@",self.categoryQuoteViewController.aLabel.text);
The first NSLog
prints the value, then straight after setting it and printing the label's value it is null
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
categoryQuoteViewController
的视图是延迟加载的,这意味着在您第一次在屏幕上显示视图之前,不会加载任何标签。因此,当您第一次访问categoryQuoteViewController.aLabel
时,它将是nil
。您可以通过访问视图控制器上的
view
属性来强制加载视图,如下所示:The problem is the view of
categoryQuoteViewController
is loaded lazily, which means none of your labels are loaded until you first display the view on the screen. So when you first accesscategoryQuoteViewController.aLabel
it will benil
.You can force the view to load by accessing
view
property on the view controller like this: