Can you programmatically set the title of a NStextfield?

kensuguro
Unregistered
 
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
Sage
Posts: 1,066
Joined: 2004.07
Post: #2
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
Quote this message in a reply
kensuguro
Unregistered
 
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
Sage
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 )

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
Quote this message in a reply
Member
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
Member
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 6,539 Sep 6, 2007 04:20 AM
Last Post: Fenris
  Another problem, this time with NSTextField Justin Brimm 10 4,803 Nov 17, 2005 12:46 AM
Last Post: 5thPeriodProductions