Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

shakeman0

macrumors 6502a
Original poster
Jul 20, 2009
632
22
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.