3

Here's what i did.

  1. Make a clean OSX project.
  2. went to main.xib and dragged a popover controller. This created 2 visible objects on on interface builder.
  3. I went to the appDelegate.h file and did

    `-@Property (assign) IBOutlet NSViewController *popVC;

  4. Then i went to the applicationDidFinishLaunching: method and did

    popVC = [[NSViewController alloc] init];

Result: I get the following error message:

enter image description here

Shouldnt objects on a nib be weak since it is already owned by the nib?

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75
Just a coder
  • 15,480
  • 16
  • 85
  • 138

1 Answers1

11

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • @Wain I might have chosen this as correct a bit too soon. One last explanation please? This behavior happens not just with NSViewController objects on the IB outlet. It happens with ALL of them. Now im really confused. Could i zip my sample project and send you so you see what i mean? – Just a coder Jun 23 '13 at 10:00
  • If you'd like to put the code on GitHub or upload somewhere and add a link here i`ll take a look. – Wain Jun 23 '13 at 10:03
  • 2
    Outlets to top level items in a xib should be strong, Any subviews of those top level objects can be added as weak IBOutlets as they are strongly referenced by the top level items. – Abizern Jun 23 '13 at 10:22
  • @Wain Abizern filled in the missing parts. Thanks guys. – Just a coder Jun 23 '13 at 12:59