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.
Asked
Active
Viewed 1.1k times
16
-
1That sounds like the exact opposite of what should happen. The placeholder text should disappear when the field is being edited. How have you set up your NSTextField? Is it bound to anything? Note that the placeholder string will only be shown if the stringValue of the text field is nil or @"". – Stephen Poletto Apr 01 '11 at 23:47
-
There is no binding for the text field and its empty too. I've edited my post to show screenshots of the editing/not editing states. – indragie Apr 02 '11 at 00:52
-
I have the same issue, did you find your answer? – Nathan H Dec 12 '11 at 16:49
3 Answers
28
Have you tried setting the placeholder through code? for example something like this:
[[textField cell] setPlaceholderString:@"hello"];

Johann Dirdal
- 1,100
- 6
- 12
20
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.

GJ Nilsen
- 695
- 9
- 27
-2
This is how I solve this problem:
- Subclass
NSTextFieldCell
; - Override
- (void)drawWithFrame:(NSRect)cellFrame
,- (void)drawInteriorWithFrame:
(if need) method(s) ofNSCell
and put all drawing code you need to those methods. Don't forget to callsuper
implementation; - Set
Class
field ofNSTextFieldCell
inInterface Builder
to your subclass; - Setup
border
in.xib
file to(I don't know name of this border);
- Turn off
Draw Background
;

Lexandr
- 679
- 1
- 6
- 22