I’m sure this is something simple but I’ve been staring at it for a bit now and I think all I need is a fresh pair of eyes to look at it, and since my cat doesn’t have a whole lot of experience with iPhone programming I’ve turned to you.
I am passing a variable of type float from a class (UIView) to another class (UIViewController) right before the variable is passed it’s value is correct but when it reaches the function it loses it’s value, it’s shown to be 0 or -2 and I’m not sure why. Like I said I’m sure it’s something simple but I just need a fresh pair of eyes to look at it
Code is below
//inside UIView
-(void)UpdateFloat
{
myFloat = myFloat + 0.01;
}
-(void)RemoveView
{
//Function Call
[viewController myFunction:myFloat];
}
//Function
-(void)myFunction:(float)myFloat
{
[myView removeFromSuperview];
[self.view addSubview:myOtherView];
[myOtherView anotherFunction:myFloat];
}
the float gets updated by a timer and when the UIView makes the function call the value of the float is correct (usually about 15.67)
any help would be appreciated
Thank you in advance,
BWC
If your float really is a float, I bet there is something else is going on somewhere else that’s manipulating that value, it’s not the message send. Search for every occurrence of that variable name.
You’ll see stuff like this happen when you accidentally do integer math on floats (which is really easy to do). Check and make sure your floats are floats and all the math is being done in floats and no int math is happening.
It’s also possible that it is a scope related thing and you are instead getting a different
myFloat, hard to tell without all the source available.