我在 .xib 文件中有一个自定义视图,我将其用作 MAAttachedWindow
的 contentViewController
。该视图中有几个 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 NSTextField
s 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
NSSecureTextField
s.
发布评论
评论(4)
我第一次遇到这个问题大约 5 年前,使用配件NSSavePanel 的视图。
我找到的解决方案是在面板关闭之前将第一响应者移至面板本身。这是我的具体方法:
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:
尝试将文本字段文本的颜色更改为红色(或任何其他颜色),您可能会看到这里发生的情况。
Try changing color of textfield text to red color (or any other color) you may get what happens here.
我得到了它!
我只需要在关闭(并随后解除分配)MAAttachedWindow 之前从其超级视图中显式删除 viewController 即可。
I got it!
I simply needed to explicitly remove the
viewController
from itssuperview
before closing (and subsequently deallocating) theMAAttachedWindow
.在将窗口设置为零之前尝试辞去所有第一响应者的职务。
Try resigning all first responders before setting the window to nil.