do something when counter = x
I have a counter that make counter++
every time one image touches anothe开发者_开发百科r image.
Now what I want to do is: if counter=2; do something
, but I always get an error:
Assignment makes pointer from integer without a cast
Here is a part of the code:
-(void)checkcollision {
if(CGRectIntersectsRect(flakeImage.frame, viewToRotate.frame)) {
counter++;
}
}
-(void)checknumber {
if(counter=2) {
viewToRotate.alpha=0;
}
}
Are you perhaps doing this:
if (counter = 2) {
// Do something.
}
This is a common error in if
statements. The correction would be:
if (counter == 2) { // Note the "==", instead of "="
// Do something.
}
This is just a guess though - I would need to see some more information about the error, or about what you want to do.
EDIT
Ah - have seen your newly posted code, confirming what I stated above. Your code reads that you are trying to assign the value '2' to counter
in the if
statement. You want the ==
to make this a check for equality.
精彩评论