NSViewController Method Called When Loaded?

Discussion in 'Mac Programming' started by shakeman0, Aug 17, 2011.

  1. shakeman0 macrumors 6502a

    shakeman0

    Joined:
    Jul 20, 2009
    #1
    Hello,

    I'm trying to do some initialization code in my view controller when it's view is added as a subview to the main window. I actually have been programming for iPhone and am use to just using the viewDidLoad method. I looked at the initWithNibName:nibOrBil bundle: nibBundleOrNil but really need a method that is called when the view is loaded like the viewDidLoad method in UIKit. Would the best way to accomplish this be through NSNotificationCenter? Any help would be greatly appreciated.

    Thanks in advance.
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    If you want to know when your view gets added as a subview, override -viewDidMoveToSuperview (and check [self superview] != nil).

    Also, there is no -viewDidLoad on NSViewController. If you want to do something after the view is loaded (but before you use it anywhere), the only thing you can do is either implement -awakeFromNib for something in your nib, or override -loadView, call super, then do your work after that.
     

Share This Page