0

Initializing in awakeFromNib seems not working.

I have PBManager.m and In ViewController.m I made property for PBManager like

@interface ViewController : UIViewController

 @property (strong, nonatomic) PBManager * pbMgr;

@end

And tried to initialize it in awakeFromNib like

- (void) awakeFromNib {
   self.pbMgr = [PBManager sharedInstance]; // singleton. would be no problem...
 }

and I used it in button action

- (IBAction)btnSendAction:(UIButton *)sender {
[self.pbMgr sendMessage:@"sendMessage" key:@"testKey" val:@"val"];

}

but this self.pnMgr in btnSendAction is null!

But it works when I initialize it in viewDidLoad.

Please tell me what's going on.

Thanks.

Hwangho Kim
  • 629
  • 4
  • 20

1 Answers1

0

You need [super awakeFromNib];

From the documentation:

You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

JBAction
  • 26
  • 3