NSToolbar 中的 NSComboBox 通过 IB 抛出异常
我想要 NSToolbar 中的 NSComboBox。我通过 IB 和 Xcode 4.2 完成此操作。我可以将组合框放在工具栏中并启动程序。第一次(而且只是第一次)应用程序启动时,当我在组合框中设置焦点时,出现以下异常:
解锁错误视图((null))的焦点,预期为 NSComboBox
下次我在组合框中设置焦点时,不会引发异常。
如果我对 NSTextField 或 searchField 执行相同的操作,则不会出现任何异常。由于我不记得在 Xcode/Objective-C 的早期版本中遇到过此类问题,我想知道这是否是一个错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有同样的问题。将测试字段设置为不可编辑对我来说不是一个选项,而且我无法使视图中的框发挥作用。
由于问题似乎与“焦点”有关,因此我转到界面生成器并将 NSComboBox 的焦点环设置为“无”。这解决了我的问题。
通过编程,可以使用
-setFocusRingType:NSFocusRingTypeNone
来完成。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
.您是否尝试过以下解决方法?
在工具栏上放置 NSComboBox 之前,请尝试在工具栏上放置一个空的 NSView 。这将为您创建一个带有空视图的工具栏项。然后将 NSComboBox 放入刚刚创建的工具栏项内的 NSView 内。
我有类似的问题,这对我有用。
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.
我也有同样的问题。将组合框的行为更改为只能选择可以修复此问题。
对我来说幸运的是,我不需要组合框是可编辑的。
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.
同样的问题,NSPanel 内的 NSComboBox。我在 IB 中将对焦环从“默认”更改为“无”。这解决了这个问题。
这里有更多背景知识。我的代码运行良好,直到进行了多次更改:从 Xcode 4.2 (Snow Leopard) 转换为 4.3 (Lion) 后出现问题。此转变还包括从 GC 迁移到 ARC。
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.