NSTextField 如何知道它的值已更改?

发布于 2024-08-29 06:40:42 字数 455 浏览 6 评论 0原文

我有一个文本字段,可以手动编辑,也可以通过另一个控件设置。 (这是一个页码,因此您可以通过输入 16 跳转到第 16 页,或者您可以使用下一页/上一页按钮上下翻页)我将文本字段的值绑定到 int page 变量。

它似乎工作正常,当您输入页码时,它会跳转,当您上下翻页时,文本框中的页码会相应变化。

然而,在某种程度上,当我上下翻页时,文本框似乎不知道它的值已经改变,因为如果我输入 1 它不会做任何事情。它不会调用绑定的设置方法或任何东西。看起来文本字段正在思考“我已经是 1,所以我不需要做任何事情”。尽管是 5 次,因为我接下来又击中了 4 次。如果我输入 1 以外的数字,它就会出现在那里。如果我然后输入 1,它会转到第 1 页,因为现在它认为它在另一页上。

问题似乎是我正在以编程方式更改文本字段的值,但某些部分没有收到消息。

这看起来是一个合理的解释吗?不管怎样,对造成这种情况的原因有什么想法吗?

谢谢

I have a textfield that can either be edited by hand, or set through another control. (It's a page number, so you can jump to page 16 by typing in 16, or you can page up and down with the next/prev buttons) I have the value of the text field bound to an int page variable.

It seems to work correctly, when you type a page number in, it jumps, when you page up and down, the page number in the text box changes appropriately.

However, at some level, when I page up and down, the text box doesn't seem to know that it's value has changed, because if I type 1 it doesn't do anything. It doesn't call the bound set-method or anything. It looks like the textfield is thinking "I'm already 1, so I don't need to do anything." Even though it was 5 because I hit next 4 times. If I type an number other than 1, it goes there. If I THEN type 1, it goes to page 1, because now it thinks it's on that other page.

The problem seems to be that I'm changing the value of the textfield programatically, but some part isn't getting the message.

Does this seem like a reasonable explanation? And either way, any ideas on what's causing it?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

拥抱我好吗 2024-09-05 06:40:42

解决方案:为了使文本字段正常运行,我需要通过绑定的实例变量来完成所有操作。

问题是“page”实例变量实际上并不存在,有一个 page 方法和一个 setPage 方法,但实际页面保存在其他地方。当我确保从下一个/上一个代码调用 setPage 方法时,它似乎有效。

Solution: in order for the textfield to behave properly, I need to do everything through the bound instance variable.

The problem was that the "page" instance variable doesn't actually exist, there's a page method and a setPage method, but the actual page is kept elsewhere. When I make sure to call the setPage method from the next/prev code, it seems to work.

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