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?

-------------Problems Reply------------

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.

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.

Category:objective c Views:1 Time:2011-12-16

Related post

  • Which should I use, -awakeFromNib or -viewDidLoad? 2008-12-18

    I recently had a problem in my app where some of the subviews I was creating in a UIViewController subclass's -awakeFromNib method were disappearing from the view. After some poking around I found that moving the code I had put in -awakeFromNib to -v

  • initWithFrame not called, but awakeFromNib is 2009-01-11

    I am trying to subclass NSOutlineView. Here is my code: OutlineViewSublcass.h: #import <Cocoa/Cocoa.h> @interface OutlineViewSubclass : NSOutlineView { } @end OutlineViewSubclass.m: #import "OutlineViewSubclass.h" @implementation OutlineViewSub

  • awakeFromNib is not called in my ViewController 2009-06-03

    I have a view controller that is created via initWithNibName, and I just found out awakeFromNib is not called. Is awakeFromNib only called when the view controller is unarchived from the Nib? (that is, initWithCoder is called) --------------Solutions

  • Moved my viewController under a NavController and now awakeFromNib and initWithCoder don't fire? 2009-07-21

    I have a somewhat complex view that I put together in a separate (View-based template) project (the View Controller was represented with orange icon in MainWindow.xib). It's far enough along now that I've decided to move it into another project where

  • Description of initWithNibName, awakeFromNib and viewDidLoad? 2009-08-06

    Is there a good overview of initWithNibName, awakeFromNib, and viewDidLoad that lays out the best way to use each of these and describes exactly what each does? I find these very confusing. In the template that's generated with a View Controller, the

  • Why won't my awakeFromNib fire? 2009-10-19

    I am starting to move more of my view hierarchy construction to IB. I have a nib file called "AlignmentViewController.xib" in which I set up my view hierarchy with AlignmentViewController as the files owner. This works fine. One of the methods I rema

  • iphone : how to preload data at a certain time of application loading, just after awakeFromNib method 2009-11-23

    in my (quite simple) application, --> i have one subview (named "Splash") loaded in the main view at launch time, like this (in my mainView class) : -(void)awakeFromNib{ [self addSubview:splash]; } --> I have also a UITableView (named "myTable"

  • What does "-(void)" mean in this function declaration? `-(void)awakeFromNib` 2009-12-27

    How come whenever I have to use awakeFromNib protocol I have to put it in this format? -(void)awakeFromNib What is the need for -(void)? --------------Solutions------------- The -(void) is used in the declaration of the method. Presumably, you are de

  • Using (void)awakeFromNib 2010-04-15

    I am trying to run an action when the application starts. The action checkAtStart is supposed to display an alert if there is no text in field1 and hide startView if there is text in field1. checkAtStart works fine if assigned to a button, but when I

  • Accessing View in awakeFromNib? 2010-04-27

    I have been trying to set a UIImageView background color (see below) in awakeFromNib [imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]]; When it did not work, I realised that its probably because the view has not loaded

  • Why are controls (null) in awakeFromNib? 2010-04-28

    This is a follow on from another question regarding why I could not set UIControls in awakeFromNib. The answer to that is that as you can see below the controls are nil in the awakeFromNib, although they are initialised to the correct objects by the

  • awakeFromNib and loadView execute for different instances 2010-05-01

    I'm trying to understand why: NSLog(@"self = %p", self); in awakeFromNib prints a different value than the same NSLog in viewDidLoad? This isn't a huge problem because I don't need the awakeFromNib but I would like to understand how it works. The cod

  • OBJ C filling arrays in awakefromnib - scope question? 2010-05-20

    I'm attempting to fill an array, called from awakeFromNib. My problem is that the variable isn't visible when I try to access it. Here's the relevant snippet: -(id)returnHaiku { return [self getOne:[self getOne:five]] // doesn't know what "five" is..

  • Programatically created ViewController and awakeFromNiB? 2010-06-08

    I am creating a viewController programatically (hopefully the right way) My problem is that I previously created the controller in IB and have code I want to call in awakeFromNib. As I currently have things viewDidLoad works fine but awakeFromNib doe

  • Cocoa performClick: in awakeFromNib not working 2010-08-05

    Im trying to call performClick: from awakeFromNib and its not working. I think its because it needs a sender and awakeFromNib has no sender. I have tried using nil,self and sender as the sender of performClick: but none seem to work. My code is - (vo

  • Should I call [super awakeFromNib]? 2010-10-21

    If i implement my own version of awakeFromNib, should I call [super awakeFromNib] at the end of my method? --------------Solutions------------- The documentation covers that perfectly. If you meant to ask about Cocoa Touch, you're not so lucky: The U

  • WebView crash while using setDrawsBackground in awakeFromNib 2011-01-04

    I have a local property which is an IBOutlet to a WebView in the NIB. For one user, a really really important one I may say it crashed but have not found any other users with the same crash. The stacktrace I got back: Application Specific Information

  • Subviews disappearing on completion of awakeFromNib 2011-03-01

    I have a view with a NSBox subview (with CA enabled for shadow) and I'm trying to add my NSView subclass to the box dynamically during awakeFromNib. There will be a varying number of these NSViews depending on the user so I've made some code that det

  • NSView initialization: -init: vs. -awakeFromNib: 2011-03-21

    I have a simple class MyView inherited from NSView and instance variable NSImage * image; in it. Class functionality is to draw image on the view. However, in -drawRect: image instance always equal nil, if it was initialized in -init: function and no

  • Why is awakeFromNib not called when the view is visited again? 2011-04-06

    I would like to know if there is a method equivalent to awakeFromNib. The problem i am facing is as follows: My app has 2 views and the 2nd view has a subclass (UIview) which i use to draw. I use a timer which is called from awakeFromNib in order to

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.155 (s). 11 q(s)