如何强制从 NSButton 在 NSTextField 中完成输入
当我的用户界面处于某种状态时,我刚刚注意到一个问题。我有一个包含两列的表视图,用户可以在这两列中输入稍后使用的数据。还有一个按钮可以作用于表视图的内容。
问题是,如果用户已在列中输入新数据,但尚未使用 tab 键或 return 键退出该字段(即光标仍在字段中并处于编辑模式),并且按旧值按钮使用的不是该字段中的当前值。
处理这个问题的最佳方法是什么?我想使用用户迄今为止输入的任何内容。
基本上,按钮代码需要告诉文本字段完成完成或退出编辑模式。但我似乎找不到一种方法可以做到这一点。
I just noticed a problem when my user-interface is in a certain state. I have a table view with two columns both of which the user can enter data that is to be used later. There's also a button which acts upon the contents of the table view.
The problem is if the user has entered new data in the column but has not yet exited the field by using the tab key or return key (i.e. the cursor is still in the field and in editing mode) and the button is pressed the old value is used not the current value sitting in the field.
What is the best way to handle this this? I want to use whatever the user has entered thus far.
Basically, The button code needs to tell the text field to finish completion or exit the editing mode. But I can't seem to find a method that will do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用绑定。在 Interface Builder 中,选择表列,然后在检查器中转到表列绑定并适当设置值内容绑定,并确保选中“连续更新值”选项。然后,对表格单元格内容的更改将立即传播。
Use bindings. In Interface Builder, select the table column and in the Inspector go to Table Column Bindings and set the Value content binding appropriately and ensure the "Continuously Updates Values" option is checked. Then changes to the table cell content will propagate immediately.
找到了答案,至少对我来说。
查明是否选择了一行,如果是则取消选择它。这会导致当前条目完成。
Found the answer, At least for me.
Find out if a row is selected and if so deselect it. This causes the current entry to be completed.
怎么样:
如果您位于
NSWindowController
内,theTargetWindowWhateverThatIs
可能是self.window
。How about:
theTargetWindowWhateverThatIs
may be, for example,self.window
if you are inside aNSWindowController
.