NSTextField Text Disappearance

I have a custom view in a .xib file that I use as a contentViewController for MAAttachedWindow . It has several NSTextField .

When I first open MAAttachedWindow , everything is fine. Text is displayed 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 text field firstResponder now empty.

The strange thing is that if I click on the "empty" text box, it will display the correct text. This can be edited and behaved accordingly if this text field has focus. As soon as something becomes firstResponder , the text will disappear again.

Update

  • The color change did not change the above behavior.
  • The color of the text does not change at any time during this process.
  • Bookmark text is also subject to the above behavior.
  • No errors occur during this process.
  • This does not happen with NSSecureTextField s.
+4
source share
4 answers

I understood!

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

+2
source

I first encountered this problem about 5 years ago with an accessory for NSSavePanel. The solution I found was to transfer the first responder to the panel before it closed. Here is 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 text field will be blank and behave strangely [savePanel makeFirstResponder:savePanel]; } 
+4
source

Try changing the color of the text field text to red (or any other color), you can get what happens here.

+2
source

Try to delay all first responders before setting the window to zero.

0
source

Source: https://habr.com/ru/post/1379535/


All Articles