11
votes

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.

2
You'd be far better off making the API reference your first resource (including superclasses of the one you're investigating). You should especially not ignore compiler errors and run log messages (like the ones you were sure to have received using the code you provided) as they usually tell you exactly what's wrong. This approach will make you a far more effective programmer. - Joshua Nozzi

2 Answers

25
votes

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).

3
votes

You should be able to use the setStringValue: method that NSTextField inherits from NSControl.

The full signature is:

- (void)setStringValue:(NSString *)aString