Problems assigning incremented values to CGPointMake
Question
I'm trying to use the following code to move through pages of a Pdf using webView.
float Y = pdfNavigateController.webView.center.y + gY;
[pdfNavigateController.webView.scrollView setContentOffset:CGPointMake(0,Y)];
The value gY is also a float and is incremented as the user selects the next page. The code is currently throwing an error 'Invalid operands to binary expression ('CGFloat' (aka 'float') and 'float *'). I'm guessing the operands are invalid as the value is a pointer but I don't know how to pass the incremented value without getting this error.
Solution
If gY is a pointer (to a float), you need to dereference it in order to access its value:
float Y = pdfNavigateController.webView.center.y + *gY;
EDIT
Make sure you've got a valid pointer (i.e., gY points to an actual float). If it's an un-initialized pointer, it won't work.
Can you please tell us how do you get gY
?
EDIT 2
I've seen you said that gY is declared as:
static float *gY = 0;
That's a NULL pointer.
And you can't dereference a NULL pointer.
When you increment it, you increment the pointer (the memory address), not the value. So your pointer actually points to garbage.
Why do you use a pointer? You should use:
static float gY = 0;
OTHER TIPS
if gY
is a pointer to a float use *gY
:
float Y = pdfNavigateController.webView.center.y + *gY;
The error rmessage: ('CGFloat' (aka 'float') and 'float *')
is saying that CGFloat
expected a float
but got a float pointer: float *
For debugging first break the operation down into accessing the value pointed to.
float gYValue = *gY;
float Y = pdfNavigateController.webView.center.y + gYValue;
It is hard to troubleshoot since you've posted very small amount of your code. However I have an idea. If the gX is an argument of a method the solution may be following:
In order to fix this problem, add the declaration of the method to the .h file for your class. Hope this will help - if not please post some more code.