cacao: ¿cuál es el significado de NSbutton remitente intValue?

I create a IBAction like the following:

- (IBAction)okButton:(id)sender {
    NSLog(@"%d",[sender intValue]);

when I repeatedly click the button, the code print out 1,0,1,0,1,0. I want to know the meaning of intValue of a sender. The reference is Returns the receiver’s value as an int. but I don't know what doesn't it 's meaning.

preguntado el 30 de julio de 12 a las 14:07

1 Respuestas

That would be the NSButton state which is an NSInteger, but you should use this enum instead:

enum {
   NSMixedState = -1,
   NSOffState   = 0,
   NSOnState    = 1

The button will usually be in NSOffState until you click it and it changes to NSOnState, then the next click changes it back again - for a simple button you don't see this state visually but for some button types (like a checkbox) the state is displayed visually.

La opción sender here will be your NSButton, and it would be more correct to use state más bien que intValue (but you'd need to cast it to NSButton primero).

Respondido 31 Jul 12, 05:07

is there any difference between using NSOnState/NSOffState and just the numbers 1/0? - Ziofil

The difference is clarity, NSOnState documents your code. Otherwise no. - MattR

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.