iDevGames Forums
Can you programmatically set the title of a NStextfield? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Can you programmatically set the title of a NStextfield? (/thread-5088.html)



Can you programmatically set the title of a NStextfield? - kensuguro - Sep 5, 2005 03: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.


Can you programmatically set the title of a NStextfield? - Nick - Sep 5, 2005 03:10 PM

Of course you can.

Code:
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


Can you programmatically set the title of a NStextfield? - kensuguro - Sep 5, 2005 11:01 PM

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.


Can you programmatically set the title of a NStextfield? - TomorrowPlusX - Sep 6, 2005 04: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 )

Code:
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


Can you programmatically set the title of a NStextfield? - Duane - Sep 6, 2005 07: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.


Can you programmatically set the title of a NStextfield? - Steven - Sep 6, 2005 08:09 AM

I've seen references to some class called NXConstantString; you may find information by searching on that (no guarantees!)