Ah Wen
Ah Wen

Reputation: 115

When loadNibName used in init, ViewController can't recieve viewDidLoad event

When I call loadNibNamed: in init, the UIViewController can't receive viewDidLoad event. But if I put call to loadNibNamed: somewhere else, it works fine. What is the reason?

-(id)init
{
   self=[super init];

   if(self){
       [[NSBundle mainBundle]loadNibNamed:@"MainView" owner:self options:nil]; 
   }
   return  self;
}

- (void)viewDidLoad
{
   [super viewDidLoad];
}

Upvotes: 0

Views: 472

Answers (1)

Puneet Sharma
Puneet Sharma

Reputation: 9484

This is because when you are writing implementation of init , you are not calling super with nib name correctly.

-(id)init {
 self = [super initWithNibName:@"MainView" bundle:nil]; 
return  self;
}

Upvotes: 2

Related Questions