Can you programmatically set the title of a NStextfield?

Post: #1
Hi, I'm a complete newbie, so please excuse my freshness. I've done some VC++ in the past with MFC, but haven't really got past the "well, isn't that just a calculator?" phase.

Anyway, I've figured out setting the title for user editable textboxes (ala currency exchange tutorial) but can't figure out how to change the text on the NStextfields that you use for labels. I'm sorry if I've got my terminology mixed up, I'm barely learning the proper vocabulary.

I'm also in the process of gathering sourcode for simple, single window, "push and go" type apps with minimal interface elements so I can learn the basics of what goes into and comes out of an interface. My second question is whether there is a simple tutorial that goes over these basics or not.. like, populating pulldown menus, figuring out which one was chosen, figuring out if the toggle is on or off, those kinds of things... I've seen apple's documentation, but it's hard to learn without actual code to look at.

Sorry this isn't really a "game programming" question.. I have to get that far first. hehe.
Quote this message in a reply
Posts: 1,066
Joined: 2004.07
Post: #2
Of course you can.

NSTextField *myField;

NSString *title = [NSString stringWithString:@"My Title"];
[myField setStringValue:title];

Obviously you can use any valid NSString in it's place.

Now I just hope that's what you meant by setting the title of the field. Smile
Quote this message in a reply
Post: #3
right on, thanx. I was missing the @ sign, hehe. If you have time can you tell me what the @ sign means? If not, I can just wait for my Cocoa books to arrive. Bear with me, I'm really just kicking off. I know I sound way too newbie-ish. hehe.

Also, any pointers to interface tutorials would be great.
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #4
The @ sign is an ObjC shortcut to allow you to create an NSString like you would a c-string literal.

E.g., the two are equivalent ( sort of )

NSString *str1 = @"A string";
NSString *str2 = [[NSString stringWithCString: "Another string"] retain];

There's more to it than that. I believe the first version will be added to a global string table by the compiler for purposes of efficiency. But for all intents and purposes they're similar.

For good tutorials, read, and for a good community Cocoa wikki, read
Quote this message in a reply
Posts: 567
Joined: 2004.07
Post: #5
yes, it's a macro of some sort. I'm actaully kind of wondering where it is... I've been hunting through the Foundation headers for a while now searching for it... It's the equivilant of calling CFString(), or something like that.

It's not magic, it's Ruby.
Quote this message in a reply
Posts: 370
Joined: 2002.04
Post: #6
I've seen references to some class called NXConstantString; you may find information by searching on that (no guarantees!)

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Creating NSImageView programmatically [fixed] Fenris 4 11,933 Sep 6, 2007 04:20 AM
Last Post: Fenris
  Another problem, this time with NSTextField Justin Brimm 10 8,283 Nov 17, 2005 12:46 AM
Last Post: 5thPeriodProductions