问题
Here's what i did.
- Make a clean OSX project.
- went to main.xib and dragged a popover controller. This created 2 visible objects on on interface builder.
I went to the appDelegate.h file and did
`-@Property (assign) IBOutlet NSViewController *popVC;
Then i went to the
applicationDidFinishLaunching:
method and didpopVC = [[NSViewController alloc] init];
Result: I get the following error message:
Shouldnt objects on a nib be weak since it is already owned by the nib?
回答1:
Outlets to view controllers should be strong
. The NIB doesn't own the objects, its just an archive. Outlets to views should usually be weak
but that's because the view is retained by its superview (the superview is usually retained by its view controller).
As an aside, you shouldn't be doing:
popVC = [[NSViewController alloc] init];
Because popVC
is being unarchived, created and set when the NIB is loaded. By creating and setting an instance yourself you're throwing the NIB version away. This applies to all outlets - the purpose of an outlet I'd to be filled in when a NIB is loaded.
来源:https://stackoverflow.com/questions/17256056/should-an-outlet-to-a-view-controller-class-be-weak-or-stong-osx-app