无法通过 IB 中的绑定和共享 NSUserDefaults 保存数据的问题

发布于 2024-08-26 06:10:55 字数 420 浏览 3 评论 0原文

我遇到了一个奇怪的问题,我无法弄清楚。我对 Interface Builder 有点陌生。我想做的事情看起来应该很简单,但由于某种原因它不起作用。

在界面生成器中,我有一个带有简单 NSTextField 的首选项窗口。我已使用控制器键“values”和模型键“test”将值绑定设置为共享用户默认控制器。我构建/运行我的应用程序并打开首选项窗口,在所述文本字段中输入一些随机值,然后关闭窗口。 Command-Q 应用程序。然后在 shell 中,我为我的应用程序执行“默认读取 com.xxx.yyy”,但无法找到键和值。话虽这么说,看起来下次我启动应用程序并更改它的值时它会起作用,但前提是我在关闭窗口之前将焦点从 NSTextField 上移开。

在 NSUserDefaults 的文档中,它说共享控制器立即保存值,我在这里错过了一些愚蠢的东西吗?

感谢您的任何帮助。

I'm having a bit of a strange issue that I can't quite figure out. I'm somewhat of a n00b to Interface Builder. What I am trying to do seems like it should be simple, but it's not working for some reason.

In interface builder I have a preferences window with a simple NSTextField. I have set the value binding to the Shared User Defaults Controller with the controller key "values" and model key "test". I build/run my app and open the preferences window, type some random value into said text field, close the window. Command-Q the app. Then in a shell i do a "defaults read com.xxx.yyy" for my app and the key and value are nowhere to be found. That being said, it seems like the next time I fire up the app and change the value it works but only if I switch focus off of the NSTextField before closing the window.

In the documentation for NSUserDefaults it says that the shared controller saves values immediately, am I missing something stupid here?

Thanks for any help.

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

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

发布评论

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

评论(1

盛装女皇 2024-09-02 06:10:55

我在被问到这个问题很长时间后才回答这个问题,以防其他人觉得它有用。

听起来您需要为绑定的文本字段设置“连续更新值”。否则,仅发送该值,并且相应地,仅当发生“最终”编辑的情况时才更新首选项。这通常是通过按 Return 键触发的,并且当您将焦点从窗口移开时也可能会发生(尽管我刚刚在我自己的应用程序之一中测试了这一点,但它似乎没有提交编辑)。

I'm answering this a long time after it was asked in case others find it useful.

It sounds like you need to set "Continuously Updates Values" for the text field you've bound. Otherwise, the value is only sent and, accordingly, the preferences only updated when something happens to 'finalise' the edit. That's usually triggered by pressing Return and probably also happens when you switch focus away from the window (though I just tested this in one of my own applications and it didn't seem to commit the edit).

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