Question

I have the following code:

- (void) awakeFromNib
{
    CGRect temp = self.buttonOne.frame;
    temp.origin.y += 50;
    self.buttonOne.frame = temp;
}

The code inside is doing nothing; when the app loads buttonOne is exactly where it is on the storyboard.

If i place the same code inside viewDidLoad thus:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CGRect temp = self.buttonOne.frame;
    temp.origin.y += 50;
    self.buttonOne.frame = temp;
}

It works and the button is moved down.

Is this because something happens between awakeFromNib firing and the view being drawn?

Any clarification would be great!

Was it helpful?

Solution

awakeFromNib will be called when the controller is unarchived from the nib file, while viewDidLoad will be called when the view tied to the controller is created.

Therefore awakeFromNib will be called before viewDidLoad. When awakeFromNib is called, the view has not been loaded yet (if it had viewDidLoad would have been called), therefore any changes to it will not affect it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top