views:

21

answers:

1

I have UITableviews that set another views 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 arent 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 labels value it is null?

+1  A: 

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;
Mike Weller
Perfect thank you.
alJaree