Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing View in awakeFromNib?
    primarykey
    data
    text
    <p>I have been trying to set a UIImageView background color (see below) in awakeFromNib</p> <pre><code>[imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]]; </code></pre> <p>When it did not work, I realised that its probably because the view has not loaded yet and I should move the color change to viewDidLoad.</p> <p>Can I just verify that I have this right?</p> <p>gary</p> <p><strong>EDIT_002:</strong></p> <p>I have just started a fresh project to check this from a clean start. I setup the view the same as I always do. The results are that the controls are indeed set to (null) in the awakeFromNib. Here is what I have:</p> <p>CODE:</p> <pre><code>@interface iPhone_TEST_AwakeFromNibViewController : UIViewController { UILabel *myLabel; UIImageView *myView; } @property(nonatomic, retain)IBOutlet UILabel *myLabel; @property(nonatomic, retain)IBOutlet UIImageView *myView; @end </code></pre> <p>.</p> <pre><code>@synthesize myLabel; @synthesize myView; -(void)awakeFromNib { NSLog(@"awakeFromNib ..."); NSLog(@"myLabel: %@", [myLabel class]); NSLog(@"myView : %@", [myView class]); //[myLabel setText:@"AWAKE"]; [super awakeFromNib]; } -(void)viewDidLoad { NSLog(@"viewDidLoad ..."); NSLog(@"myLabel: %@", [myLabel class]); NSLog(@"myView : %@", [myView class]); //[myLabel setText:@"VIEW"]; [super viewDidLoad]; } </code></pre> <p>OUTPUT:</p> <pre><code>awakeFromNib ... myLabel: (null) myView : (null) viewDidLoad ... myLabel: UILabel myLabel: UIImageView </code></pre> <p>I would be interested to know if this should work, from the docs it looks like it should, but given the way I usually set things up I can't quite understand why it does not in this case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload