1
votes

In my iPhone App.

I have two view controllers.

They have SuperClass-SubClass Relation.(Inheritance).

Let Say ViewController1 is a SuperClass and ViewController2 is a SubClass.

They both share a common nib file of super class.

So, Ideally all the methods of ViewController1 is inherited to ViewController2 (If I am not overriding it in ViewController2).

So, To check this When I am

My viewcontroller2 Loads viewDidLoad not called from super class.

**ViewController1

-ViewDidLoad

-ViewWillApper


**ViewController2

Other methods but I am not writing ViewDidLoad and ViewWillAppear
//---------------

So,When this separate page ViewController2 is called. ViewDidLoad is not called of SuperClass. But ViewWillAppear is called.

2

2 Answers

1
votes

It may be that -viewDidLoad: is only called once because the same nib file is shared between the two classes. After the first time the nib is loaded into memory, -viewDidLoad: is called. It isn't called a second time because it's simply being reused from memory where it already resides, so it does not need to be reloaded. This would explain why -viewWillAppear: is still called.

UIViewController Class Reference: -viewDidLoad:

viewDidLoad

Called after the controller’s view is loaded into memory.

  • (void)viewDidLoad

Discussion

This method is called after the view controller has loaded its associated views into memory. This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method. This method is most commonly used to perform additional initialization steps on views that are loaded from nib files.

0
votes

How can you say that your ViewController1 and ViewController2 are having Inheritance?? Post the code of ViewController2.h file.

Are you doing like

@interface ViewController2 : ViewController1 {
}

if you are doing like above then only you can say that you are inheriting the VC2 from VC1. And only then you will be able to call viewDidLoad of VC1.

If you are using only 1 xib files and 2 VC and the case you discuss does not mean that you are inheriting.

when you write

ViewController1 *vc1 = [[ViewController1 alloc] initWithNibName:@"ViewController1"];

and

ViewController2 *vc2 = [[ViewController2 alloc] initWithNibName:@"ViewController1"];

this means that you reuse your .xib file and does not inherits the class...