Xcode, how to use IBOutlet for marking when used in function

I have a link to my label:

@property (weak) IBOutlet NSTextField *scoreBox; 

right, and I'm trying to access it like this:

 void namedfunction(button) { if (button == button) { score = score + 100; [scoreBox setIntValue:score]; // ^ error } } 

and I get this error:

AppDelegate.m: 52: 10: Using the undeclared identifier 'scoreBox'

What am I doing wrong?

+4
source share
1 answer

Use

 [_scoreBox setIntValue:score]; 

or

 [self.scoreBox setIntValue:score]; 

* Also make sure that you have finished comparing the same button: button==button .

EDIT 2:

How is your code:

 int perus(int nappi){ } 

Change it to:

 - (NSInteger *)perus:(NSInteger *)nappi{ //all should do inside, rest are OK. } 

EDIT:

I'm not sure about the following as I found it here

* I would suggest you switch to the obj-c method instead of using the C function for this kind of thing.

The C function is just that the block of code is not attached to anything else. Your instance variable is bound to every controller object. Therefore, when you call printChatter (), there is no way to find out which instance of the controller you want to use. You can add an object variable to your function:

 void namedfunction(const void *button, const void *appDele){ NSTextField *myButton=[appDele scoreBox]; .... } 

Strike>

+5
source

All Articles