CoreData结合NSTableView的失去输入焦点时,项目变更,但前提是整理 [英] CoreData-bound NSTableView loses input focus when items change, but only if sorted

查看:290
本文介绍了CoreData结合NSTableView的失去输入焦点时,项目变更,但前提是整理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSTableView的,其中在实体名称的模式,通过一个NSArrayController势必CoreData模型实例集合的对话框。该表显示了名称管理​​型对象,在一列的数组。这个效果很好。

I have an NSTableView in a dialogue box which is bound to a collection of CoreData model instances via an NSArrayController in 'Entity Name' mode. The table displays the names of the array of managed objects in a single column. This works well.

表中的行名称可编辑。如果用户编辑姓名时没有申请表,然后编辑将正常进行排序。 pressing返回后,新的名字被记录下来,输入焦点停留在NSTableView的。但是,如果在表视图中的列标题的顺序来排序名称的表格被点击后,输入焦点走错的编辑后。它停留的窗口,或者更宽的视图(不知道哪个)之内,但是它超出了表的;对焦环消失以及从蓝色高亮显示项目的背景颜色为灰色。 pressing标签弹出输入焦点放回表视图一次。

The names in the table rows are editable. If the user edits a name when there is no sorting applied to the table then editing proceeds normally. After pressing Return, the new name is recorded and input focus stays in the NSTableView. However, if the column heading in the table view is clicked upon in order to sort the table of names, input focus goes astray after editing. It stays within the window, or wider view (not sure which), but it goes out of the table; the focus ring vanishes and the background colour of the highlighted item changes from blue to grey. Pressing Tab pops input focus back into the table view again.

此的发生,如果表的内容进行排序。如果不断更新的价值被选择用于绑定,这是灾难性的分钟的任何字符输入,表视图似乎想重新排序本身(这是确定)和重点跳出它(这不是为用户确定在试图输入的东西)的中间。

This only happens if the table contents are sorted. If "Continuously Updates Value" is chosen for the binding, it's catastrophic as the minute any characters are entered, the table view seems to want to re-sort itself (that's OK) and focus jumps out of it (that's not OK as the user was in the middle of trying to type something).

至于系统的这个方面来讲,有没有code - 这一切既定界面生成器绑定完成。 presumably,我无意中设置或清除一些选项,我不应该。

As far as this aspect of the system is concerned, there's no code - it's all done with bindings established in Interface Builder. Presumably, I've inadvertently set or cleared some option that I shouldn't have.

在情况下,它有助于读者搞清楚这是怎么回事 - 我也有连接到其中包含NSTableView的对话框模态表。该表是用来编辑表格视图中选择项目的详细信息。在此的控制也使用相同NSArrayController的作为对话框后面的片绑定到CoreData模型相连。同样的问题被认为是 - 只要一个新的名字被键入中,焦点拉回对话框'背后'模态片

In case it helps the reader figure out what's up - I also have a modal sheet attached to the dialogue box containing the NSTableView. The sheet is used to edit the details of an item selected in the table view. The controls in this are also connected with bindings to the CoreData model using the same NSArrayController as the dialogue box 'behind' the sheet. The same problem is seen - as soon as a new name is typed in, focus is pulled back to the dialogue box 'behind' the modal sheet.

涉及的仅code是用来处理编辑此项目的行动,并启动模式会话的表。

The only code involved is that used to handle the 'edit this item' action and start the modal session for the sheet.

这是怎么回事?焦点要去哪里,以及为什么被感动,只是因为重新排序在NSTableView的?

What's going on? Where is the focus going and why is being moved just because of re-sorting in the NSTableView?

谢谢!

推荐答案

NSArrayController的有实体自动重新排列内容打勾在相关Interface Builder的督察小组。这是没有做什么我想这会做,并且是重点偷问题的原因。

The entities NSArrayController had "Auto Rearrange Content" ticked in the relevant Interface Builder inspector panel. This wasn't doing what I thought it would do and was the cause of the focus stealing problem.

我终于通过创建一个裸露的骨头刚刚添加名称表视图CoreData应用收窄下来。几乎没有code必需的; 99.5%Interface Builder中和绑定,只有一个额外的插座和胶水code一行来告诉约由code界面生成器必须在应用程序委托实例化的托管对象上下文CoreData模型阵列控制器自动生成的。设置自动重新排列内容标志测试程序又勾起了奇怪的输入焦点的行为。

I finally narrowed this down by creating a bare bones CoreData application which just added names to a table view. Almost no code required; 99.5% Interface Builder and bindings, with just an extra outlet and a single line of glue code to tell the array controller for the CoreData model about the Managed Object Context instantiated in the application delegate by code that Interface Builder had auto-generated. Setting the "Auto Rearrange Content" flag in the test program provoked the same strange input focus behaviour.

所以,如果你有偷的焦点问题,通过阵列控制器绑定到CoreData对象表,检查你的阵列控制器的自动重排旗帜!

So if you've got focus stealing problems with a table of objects bound to CoreData through an array controller, check your array controller's auto-rearrange flag!

这篇关于CoreData结合NSTableView的失去输入焦点时,项目变更,但前提是整理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆