0

This is an OS X application. I am designing a custom sheet. Within my XIB file I have the sheet's window and a subclass of NSViewController which is responsible for controlling the views within the window/sheet. The owner of the XIB is another controller class.

I placed an NSTextField into the window's content view. In my NSViewController I created an IBOutlet declaration for the NSTextField and ensured the outlet was properly connected in the XIB.

I overrode -[NSViewController setRepresentedObject:] and within that method I am looking at the representedObject and depending on it's properties I am either removing the NSTextField from it's superview or I'm adding it back into the superview.

The first time I display my sheet with a representedObject that dictates the textfield should be removed from the superview. This works just fine.

The second time I display my sheet with a representedObject that dictates the textfield should be added back to the superview my application crashes with EXC_BAD_ACCESS when calling -[NSView addSubview:].

Running Instruments shows that the NSTextField was a Zombie at the time I tried to add it back to the superview. Instruments also indicates that every call to retain/release/autorelease was performed by either AppKit or Foundation - so at no point does any of my code increase or decrease the retain count. In fact the only two lines that reference the IBOutlet in my code are a call to -[NSView removeFromSuperview] and -[NSView addSubview:].

Am I doing something wrong or is this a bug in OS X? An IBOutlet should never be deallocated unless the XIB is unloaded.

Carter
  • 4,738
  • 2
  • 22
  • 24

1 Answers1

1

Well naturally I figured it out like 2 minutes after I posted my question.

There are actually 2 textfields in my XIB both of which have identical behavior as described in the question. Only one of the textfields was turning into a NSZombie which made things more confusing.

Well when I was designing the XIB I laid down one NSTextField, configured it, and then copied it by holding Option while dragging the NSTextField. I did ensure the outlets were setup properly for the copied NSTextField, but for some reason the objects remained the same.

The solution was to delete the offending NSTextField and then drop a fresh one from the palette and configure it that way.

Carter
  • 4,738
  • 2
  • 22
  • 24
  • Please file a descriptive bug report to http://bugreport.apple.com - if this is indeed what happened, it's an Xcode bug that should definitely be fixed. – Joshua Nozzi Jun 23 '12 at 14:32
  • I think I will work on duplicating the problem in a sample project and submit it as a bug if it is in fact reproducible. Thanks. – Carter Jun 23 '12 at 21:09