I set the placeholder text of my NSTextField in Interface Builder, but the placeholder text doesn't show until I click inside the text field to edit it.
The NSTextField class uses the NSTextFieldCell class to implement its user interface. Text fields display text either as a static label or as an editable input field.
var delegate: NSTextFieldDelegate? The text field’s delegate. Requests permission to begin editing a text object. Posts a notification to the default notification center that the text is about to go into edit mode. Posts a notification when the text changes, and forwards the message to the text field’s cell if it responds.
The parent class, NSControl, provides the methods for setting the values of the text field, such as stringValue and doubleValue. There are corresponding methods to retrieve values. In macOS 12 and later, if you explicitly call the layoutManager property on your text field, the framework will revert to a compatibility mode that uses NSLayoutManager.
func selectText(Any?) Ends editing in the text field and, if it’s selectable, selects the entire text content. A Boolean value that indicates whether the text field is editable and accepts first responder status.
Have you tried setting the placeholder through code? for example something like this:
[[textField cell] setPlaceholderString:@"hello"];
Have you bound the NSTextField data in Interface Builder? If so, you have to set the "Multiple Values Placeholder", "No Selection Placeholder" and "Null Placeholder" in the bindings tab in your Utilities inspector. While youre at it, you could set the "No Applicable Placeholder" as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With