text field placeholder

i have a search field, how do i change the placeholder of it in my code?

anyone???

Do you have any idea how annoying you are with your post bumping? Do you even bother to read the documentation? You know the technical name for the placeholder string, you know that it’s a text field, and 30 seconds of searching google would tell you that it’s the text field’s cell that does the magic… how is it so difficult for you to figure this out yourself? Are you just too lazy to do any of your own legwork? You shouldn’t be programming anything if you can’t figure some of this out yourself, especially considering how much time you appear to be spending working on these projects. Let me walk you through the short process it took me to arrive at the few lines of code it took to add a placeholder to a text field…

  • I went to the text field documentation, to make sure there wasn’t a simple command that I could issue in applescript that would add a placeholder string to the text field directly. Nope. Oh well. Better read the whole doc anyways, just in case.

  • Since I know through experience/googling/word-of-mouth/whatever that the text field’s cell, and not the text field itself, handles the placeholder string, I looked at the documentation for the nstextfieldcell to see what I could see. We find that all we need to do is call “setPlaceholderString” on our text field’s cell to get our task done. Let me interject upon myself here to explain something…

  • OK, so we’re set. It’s the cell that does all the work. Now what? Since we’re great readers and we’ve read the documentation and payed great attention, we know that there’s no “cell” property of a text field in the docs. Oh NO! I’m going to cry for a bit then give up. Or maybe I’ll post ANOTHER post to macscripter to make somebody else do it for me because I don’t actually want to learn anything today, I just want to succeed with no obstacles. Oooor… maybe I could go back to the docs and read some more. Remember the important relationships my brain pointed out above? Not only is it important to know where we are, in cocoa programming it’s VERY important to know where we’re coming FROM. A text field isn’t just a text field. It’s also a control, a view, a responder, and an object. Wow! Does text field have a identical twin sister, because I’m in love. The object hierarchy is your pal, your buddy, your friend. Once you grasp this, you’ll have no problem understanding that if you work your way up the chain of objects, you’ll usually find things you need or didn’t expect your child object to do in the abilities that it’s parent objects possess. It took one click to find that the text field’s parent object, the control (NSControl) can tell us what our text field’s cell is.

  • At this point we have everything we need. We know that we’re going to call a method of our text field’s cell to set it’s placeholder string. Hmm, but how could we possible approach such a statement? What would it be worded like? But wait, applescript is an english-like language… perhaps it’s as easy as putting the following single line of code in the awake from nib handler for the text field…

call method "setPlaceholderString:" of (cell of theObject) with parameter "test"

fiftyfour123, it took me 6 times longer to write this long-winded, passive-aggressive, sarcastic, probably insulting (intentionally) love letter than it did for me to simply read the docs, do some experimentation, and come up with a solution. I certainly don’t want to discourage you from learning, but this is FUNDAMENTAL stuff. I’m happy to help people with fundamental stuff, but it’s the post-bumping that set me off, and I’ve commented about it before. Get real, man! What makes you think that being a pushy, greedy, brat is going to make people want to help you? It wasn’t even 24 hours before you were back online nagging us about why we hadn’t helped you already. Do it your d@mned self! I don’t have the answer to ANY of your questions on the top of my head. I have to sit down and spend my time to research and test your problems should I choose to help you, as does everyone else. Perhaps if you spent more time really learning about programming by READING and taking the time to UNDERSTAND what you read, you’ll gain the skills you need to figure out these simple tasks and to allow your projects to naturally evolve into more complex ones.

STOP BUMPING POSTS!!! Spend less time waiting for answers and more time finding them yourself. It’s good for you and your brain will thank you later.

Well said. I tried the setPlaceholderString method before. I couldnt get it to work, because i tried this:

call method "setPlaceholderString:" of class "NSTextField" with parameters {theTextField, theString}

now i see that i had worded it wrong. Thank you for your help.

And by the way, I know exactly how you feel, I’m a member of some forums where i’m in your position (always getting annoyed at people that don’t search). So, thank you for pointing out that i am the same kind of person i get annoyed at. I do know how to read documentation. I would much rather search for my answer myself and find it instantly rather than waiting for a response on a forum. So, whenever i have a question i go to google, and search for about 15 or 20 minutes, when i can’t find anything, I take a quick look at the documentation in Xcode. Then when i can’t find anything i come to the forum.

I’m new with cocoa methods, so i still have a lot to learn. I’ve never used (let alone known of) the object hierarchy, so thatnks for mentioning that. I also never understood the cocoa references in the Xcode documentation either, so thanks again for saying what that means.

I bump my topics, because my experience with getting responses in my posts is not a good one. I usually wait a week or so before i bump a topic. And the main intention in bumping a topic is to get it back near the top of the list where it may or may not get more views.

Anyway, thanks for your help.

FWIW, I didn’t look at this topic right away because of the vague title (bumping doesn’t help if I won’t even read the topic). When I did read it, I was put off by the (trivial) difference between “text field” and “search field”.

You failed to mention this in your first post. That certainly doesn’t help when it comes to my “which posts should I read right now” scale.

I’m sorry, i didn’t realize that i put text field in my topic title. But arent they relativley the same in the way they handle text? And i’ll try to include more in my posts.

NSSearchField is a subclass of NSTextField.

makes sense…