On the iPhone I use UIViewController's viewDidLoad to run code to set up the view.
UIViewController
viewDidLoad
How can I do that with NSViewController?
NSViewController
I've tried loadView but it doesn't work...
loadView
I figured it out within minutes of posting my comment. Adding my finding as an answer because it is an example which is missing in the docs. The below code will give you the viewDidLoad method that you want. Its so easy in a way that i wonder why Apple has not implemented it yet in OS X.
- (void)viewWillLoad { if([NSViewController instancesRespondToSelector:@selector(viewWillLoad)]) { [super viewWillLoad]; } ... } - (void)viewDidLoad { if([NSViewController instancesRespondToSelector:@selector(viewWillLoad)]) { [super viewDidLoad]; } } - (void)loadView { BOOL ownImp = ![NSViewController instancesRespondToSelector:@selector(viewWillLoad)]; if(ownImp) { [self viewWillLoad]; } [super loadView]; if(ownImp) { [self viewDidLoad]; } }
Original source: http://www.cocoabuilder.com/archive/cocoa/195802-garbage-collection-leaks-and-drains.html
2.1m questions
2.1m answers
60 comments
57.0k users