I have an Xcode project, and in my UIView.h I have this like of code:
#define FINGER_SIZE 20
Tell me please, how can I change the value of FINGER_SIZE, from another UIView.
I have SecondView, and UIButton. I need something like:
-(IBAction)changeSize
{
//Change FINGER_SIZE from 20 to 50
}
The “changeSize” action I have in my SecondView, and #define FINGER_SIZE 20, I have in UIView.h
Thank you.
The
#definepreprocessor construct does not define a variable, it defines a constant. It is not possible to change the value ofFINGER_SIZE, because it does not exist by the time the Objective C compiler starts looking at your code: it’s replaced by20by then.What you are looking for is a global variable. Declare it in the header like this
and then define it in a
.mfile like this:Now you have an assignable variable that you can change freely from any method that sees the declaration.