开发者

UILabels dont update on first load of the view.

I have UITableviews that set another view's UILabels 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 lab开发者_如何转开发el's value it is null.


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 access categoryQuoteViewController.aLabel it will be nil.

You can force the view to load by accessing view property on the view controller like this:

/* Force the view to load so we can set the labels */
categoryQuoteViewController.view;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜