UILabels在视图的第一次加载时不更新。
问题描述:
我有UITableview
s根据所选的行设置另一个视图的UILabel
s。UILabels在视图的第一次加载时不更新。
在第一次选择任何行时,视图会加载空标签(没有设置),只要我导航回来,然后当我选择一行后,它完全加载。
为什么第一次选择时不设置标签?
我有以下代码:
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
。
答
问题是categoryQuoteViewController
的视图被懒惰地加载,这意味着在第一次在屏幕上显示视图之前,没有加载标签。所以当你第一次访问categoryQuoteViewController.aLabel
它将是nil
。
您可以强制鉴于这样的视图控制器*问view
属性加载:
/* Force the view to load so we can set the labels */
categoryQuoteViewController.view;
+0
完美的谢谢。 – jarryd 2010-07-16 10:26:43
如果你的第二个的NSLog给出%@为零,那么无论self.categoryQuoteViewController或self.categoryQuoteViewController.aLabel必须无。你检查过了吗?只需将它们打印为%x。 – mvds 2010-07-16 00:47:22
只是试过,它不是零。但self.categoryViewController.aLabel为空? – jarryd 2010-07-16 01:07:30