Change the text in a NSTextField programmatically?

Conor Taylor picture Conor Taylor · Jan 22, 2011 · Viewed 18.7k times · Source

I am used to doing this in Cocoa-touch, so I assumed it would be quite simple. I have already tried:

field.text = [nsstring stringwithformat:@"%i", number];
[field setText:@"%i", number];

and setString, all to no avail.

Answer

grahamparks picture grahamparks · Jan 22, 2011

This will work:

[field setStringValue:[NSString stringWithFormat:@"%i",number]];

If it doesn't do anything, it probably means field isn't set to point to the field (e.g. by making a connection in Interface Builder).