消失的 NSTextField 文本

发布于 2024-12-13 19:42:35 字数 639 浏览 2 评论 0 原文

我在 .xib 文件中有一个自定义视图,我将其用作 MAAttachedWindowcontentViewController。该视图中有几个 NSTextField

当我第一次打开 MAAttachedWindow 时,一切都很好。文本显示在所有相关文本字段中。然后,如果我关闭窗口(将其设置为 nil),然后再次调用它(使用与 contentViewController 相同的自定义视图重新初始化),最后一个 < code>firstResponder 文本字段现在为空。

奇怪的是,如果我单击“空”文本字段,它会显示正确的文本。可以对其进行编辑,并且只要该文本字段具有焦点即可正常运行。一旦其他内容成为 firstResponder,文本就会再次消失。

更新

  • 更改颜色并没有改变上述行为。
  • 在此过程中,文本颜色不会随时发生变化。
  • 占位符文本也受上述行为的影响。
  • 在此过程中任何时候都不会出现错误。
  • NSSecureTextField 不会发生这种情况。

I have a custom view in a .xib file, which I use as the contentViewController for an MAAttachedWindow. The view has several NSTextFields in it.

When I open the MAAttachedWindow first time, everything is fine. Text shows up in all relevant text fields. Then, if I close the window (which sets it to nil) and then call it again (which reinitializes, using the same custom view as the contentViewController), the last firstResponder text field is now blank.

The strange thing is that if I click the "empty" text field, it shows the correct text. This can be edited, and behaves appropriately as long as this text field has focus. As soon as something else becomes firstResponder, the text vanishes again.

Updates:

  • Changing the color did not change the aforementioned behavior.
  • The text color does not change at any time during this process.
  • Placeholder text also is subject to the aforementioned behavior.
  • No errors are occurring at any time during this process.
  • This does not happen to NSSecureTextFields.

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

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

发布评论

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

评论(4

抠脚大汉 2024-12-20 19:42:35

我第一次遇到这个问题大约 5 年前,使用配件NSSavePanel 的视图。
我找到的解决方案是在面板关闭之前将第一响应者移至面板本身。这是我的具体方法:

- (void)windowDidEndSheet:(NSNotification *)notification

    NSSavePanel *savePanel = [(XSDocument *)[self document] savePanel];
    if (!savePanel)
        return;
    // this fixes a bug where on next opening one of accessory view's text field will be blank and behave strangely
    [savePanel makeFirstResponder:savePanel];
}

I first encountered this problem about 5 years ago with accessory view of a NSSavePanel.
The solution that I've found was to move the first responder to the panel itself, before it's closed. Here's my exact method:

- (void)windowDidEndSheet:(NSNotification *)notification

    NSSavePanel *savePanel = [(XSDocument *)[self document] savePanel];
    if (!savePanel)
        return;
    // this fixes a bug where on next opening one of accessory view's text field will be blank and behave strangely
    [savePanel makeFirstResponder:savePanel];
}
浅黛梨妆こ 2024-12-20 19:42:35

尝试将文本字段文本的颜色更改为红色(或任何其他颜色),您可能会看到这里发生的情况。

Try changing color of textfield text to red color (or any other color) you may get what happens here.

不如归去 2024-12-20 19:42:35

我得到了它!

我只需要在关闭(并随后解除分配)MAAttachedWindow 之前从其超级视图中显式删除 viewController 即可。

I got it!

I simply needed to explicitly remove the viewController from its superview before closing (and subsequently deallocating) the MAAttachedWindow.

双马尾 2024-12-20 19:42:35

在将窗口设置为零之前尝试辞去所有第一响应者的职务。

Try resigning all first responders before setting the window to nil.

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