如何强制从 NSButton 在 NSTextField 中完成输入

发布于 2024-09-28 08:21:50 字数 273 浏览 6 评论 0原文

当我的用户界面处于某种状态时,我刚刚注意到一个问题。我有一个包含两列的表视图,用户可以在这两列中输入稍后使用的数据。还有一个按钮可以作用于表视图的内容。

问题是,如果用户已在列中输入新数据,但尚未使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残花月 2024-10-05 08:21:50

使用绑定。在 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.

远昼 2024-10-05 08:21:50

找到了答案,至少对我来说。

查明是否选择了一行,如果是则取消选择它。这会导致当前条目完成。

- (void) completeTableEntry 
{
    // If a column is selected ensure it is completed
    NSInteger sr = [keyValueTable selectedRow];
    if (sr != -1) {
        [keyValueTable deselectRow:sr];
    }
}

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.

- (void) completeTableEntry 
{
    // If a column is selected ensure it is completed
    NSInteger sr = [keyValueTable selectedRow];
    if (sr != -1) {
        [keyValueTable deselectRow:sr];
    }
}
抱着落日 2024-10-05 08:21:50

怎么样:

[theTargetWindowWhateverThatIs endEditingFor:nil];

如果您位于 NSWindowController 内,theTargetWindowWhateverThatIs 可能是 self.window

How about:

[theTargetWindowWhateverThatIs endEditingFor:nil];

theTargetWindowWhateverThatIs may be, for example, self.window if you are inside a NSWindowController.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文