I have an IBAction instance method that is connected to a slider, and displays the slider value in a Text Field that has the name datacellR1. A copy of the code is below, followed by a question. Both methods are in the @implementation section of the View2Controller.m file.
- (IBAction)slider1Change:(id)sender
{
float pctVal1 = [slider1 floatValue]; // this works
[datacellR1 setFloatValue:pctVal1];
[View2Controller CalculateUpdatedTotal ]; // This method needs to work with the datacellR1 contents, but I can’t access it.
}
-(void)CalculateUpdatedTotal
{
// -------- do some work with datacellR1 ----
// This function fails with an error
float newValue = [datacellR1 floatValue];
//some other code goes here
}
The error in slider1Change is that CalculateUpdatedTotal method is not found. If I change CalculateUpdatedTotal from an instance method to a class method, the error is that the Instance variable datacellR1 accessed in a class method.
Any suggestions on how I can make this work?
CalculateUpdatedTotal, as written, is also an instance method. Therefore, to invoke it, you should pass the message toself, not the class (View2Controller):By the way, it’s conventional to begin method names in Objective-C with a lower-case letter.