1

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!

Bassel
  • 452
  • 5
  • 21

1 Answers1

1

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.

Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • so the application knows nothing about the coordinates of any of the views when awakeFromNib is called, and whatever changes it makes will be overridden? Which function is called to set the initial coordinates of the views from the storyboard? – Bassel Feb 26 '13 at 21:21
  • @Bassel when awakeFromNib is called the view does not really exist yet, since it has not been loaded, so any change you make will not do anything. The initial coordinates will be known when viewDidLoad is called, note that this may different than the final coordinates, since views resize to fit the contents of the controller. – Oscar Gomez Feb 26 '13 at 21:25
  • well i disabled views autoresizing and disabled autolayout so this shouldn't happen, and the coordinates when I enter viewDidLoad will hopefully be the final coordinates that will be displayed. Thanks for the answer! – Bassel Feb 26 '13 at 21:28