NSComboBox in NSToolbar via IB throws exception

764 Views Asked by At

I want an NSComboBox in an NSToolbar. I do it via IB and Xcode 4.2. I can place the comboBox in the toolbar and start the program. The first time - and only the first time - the app starts, I get the following exception when I set the focus in the ComboBox:

Unlocking Focus on wrong view ((null)), expected NSComboBox

The next time I set the focus in the combobox, no exception is raised.

If I do the same with an NSTextField or a searchField, I do not get any exception. Since I do not remember to have had such issues in earlier version of Xcode/Objective-C, I'm wondering, if this is a bug.

4

There are 4 best solutions below

0
On

Have you tried the following workaround yet?

Before dropping a NSComboBox in the toolbar try to drop an empty NSView on the toolbar. This should create a toolbar item with an empty view for you. Then drop the NSComboBox inside the NSView inside the toolbar item you just created.

I had similar issues and this worked for me.

0
On

I have the same problem. Setting the test field non-editable was not an option for me, and I couldn't get the trick with the Box inside the View to work.

Since the problem seems to be connected to "focus", I went to the interface builder and set the focus ring to "None" for the NSComboBox. This fixed the problem for me.

Programmatically this can be done using -setFocusRingType:NSFocusRingTypeNone .

0
On

Same problem, with NSComboBox inside a NSPanel. I changed focus ring from "default" to "none" in IB. This resolved the issue.

Here is a little more background. My code ran fine until multiple changes were made: The problem appeared after converting from Xcode 4.2 (Snow Leopard) to 4.3 (Lion). Also this transition included moving from GC to ARC.

0
On

I had the same problem. Changing the behaviour of the combo box to be only selectable fixes this.

Lucky for me, I didn't need the combo box to be editable.