tags:

views:

84

answers:

3

Hey guys,

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

A: 

Well, I don't understand you, because you say you pass from UIView to UIViewController. But in your code, you first call an function in the UIViewController, which have to be [self myFunction:myFloat] by the way, and in that function you call your UIView.

Tim van Elsloo
No the First line of code is in my UIView, I'm calling out to a function in the ViewController which the viewController is then removing one view and adding another view and then calling a function in the second view and passing in the float that it was given by the first view. but even before it makes that call the float has lost it's value
BWC
+1  A: 

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.

slf
I was missing the import statement which was causing the signature of my method to not be found so the passed in variable was losing it's value...I got it all taken care of, thank you for your help
BWC
that sort of makes sense, it would probably be treated as an (id) instead of a (float) causing all sorts of strange things to happen because float is not a class.
slf
A: 

Ok Guys,

I think I've figured out why the float isn't retaining it's value but the reason also baffles me.

when I'm calling the ViewControllers function in the UIView Xcode is showing the warning that there is no method and that methods without a matching signature will assume to return(id) and pass '...' as arguments

I understand what this warning means but what I don't understand is that I have the method declared in the header of my viewController

-(void)myFunction:(float)myFloat;

I also have another view that calls functions to the view controller and it's not displaying that warning...I'm pretty sure this is the reason the float isn't retaining it's value but I don't know why it can't see the method signature

BWC
I figured it out guys, I was missing my import statement...see I knew it was going to be something simple
BWC