William Sham
William Sham

Reputation: 13239

What is [super awakeFromNib]; used for?

I often see this line of code

[super awakeFromNib]

in the awakeFromNib method in the implementation of a view controller

My understanding is it is telling the super class of this view controller (which would be the window) to awakeFromNib. Am I right? If so, why do we have to tell the window to awake in the awakeFromNib method of a UIView Controller sub-class?

Upvotes: 2

Views: 1909

Answers (2)

Ajeet Pratap Maurya
Ajeet Pratap Maurya

Reputation: 4254

What David said above is correct,

Now for your question "why do we have to tell the window to awake in the awakeFromNib method of a UIView Controller sub-class?"

if there is any custom modification or any data that you want to load before your ViewController loads we should use the awakeFromNib.

awakeFromNib is called when the controller itself is unarchived from a nib.

Upvotes: 1

David Gelhar
David Gelhar

Reputation: 27900

My understanding is it is telling the super class of this view controller ...

right so far...

(which would be the window)

oops - that's the source of your confusion.

The "super class of the view controller" is UIViewController. "super" is referring to the base class that your UIViewController sub-class inherits from; it doesn't have anything to do with the window that encloses your view.

So, what this is doing is invoking the default awakeFromNib implementation of a basic UIViewController, in addition to whatever you're doing in your sub-class implementation.

Upvotes: 5

Related Questions