Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the text in a NSTextField programmatically?

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.

like image 911
Conor Taylor Avatar asked Jan 22 '11 17:01

Conor Taylor


2 Answers

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

like image 176
grahamparks Avatar answered Nov 18 '22 02:11

grahamparks


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

The full signature is:

- (void)setStringValue:(NSString *)aString
like image 3
John Parker Avatar answered Nov 18 '22 03:11

John Parker