PDA

View Full Version : Can you programmatically set the title of a NStextfield?


kensuguro
2005.09.05, 07:01 PM
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.

Nick
2005.09.05, 07:10 PM
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. :)

kensuguro
2005.09.06, 03:01 AM
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.

TomorrowPlusX
2005.09.06, 08:31 AM
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 http://cocoadevcentral.com, and for a good community Cocoa wikki, read http://cocoadev.com

Duane
2005.09.06, 11:02 AM
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.

Steven
2005.09.06, 12:09 PM
I've seen references to some class called NXConstantString; you may find information by searching on that (no guarantees!)