Reputation: 4716
I got the x and y by a UITapGestureRecognizer set on the screen, after having obtained the location I find the object touched, so I put the conditions, but does not work. Maybe I put the wrong conditions in objective C? Xcode gives no errors but the function does not work.
-(void)tappedMapOniPad:(int)x andy:(int)y{
NSLog(@"the x is: %d", x);
//the x is: 302
NSLog(@"the y is: %d", y);
//the y is: 37
if((121<x<=181) && (8<y<=51)){ //the error is here
self.stand = 431;
}else if ((181<x<=257) && (8<y<=51)){
self.stand=430;
}else if ((257<x<=330) && (8<y<=51)){
self.stand = 429;
}
NSLog(@"The stand is %d", self.stand);
//The stand is 431
}
How can I do?
Upvotes: 0
Views: 513
Reputation: 46533
(121<x<=181)
kind of expression is invalid in Obj-c.
Use, (x>121 && x<=181)
Your full code will be like :
if((x>121 && x<=181) && (y>8 && y<=51)){ //the error is here
self.stand = 431;
}
else if ((x>181 && x<=257) && (y>8 && y<=51)){
self.stand=430;
}
else if ((x> 255 && x<=330) && (y>8 && y<=51)){
self.stand = 429;
}
Or you can optimize it as:
if(y>8 && y<=51){
if (x> 257 && x<=330) {
self.stand = 429;
}
else if(x>181){
self.stand=430;
}
else if(x>121){
self.stand = 431;
}
}
Upvotes: 1
Reputation: 52227
121<x<=181
let's assume x := 10 121<10<=181
-> false<=181
-> 0<=181
-> true
you have to do it step by step.
((121 < x) && (x <=181))
let's assume x := 10 ((121 < 10) && (10 <=181))
->false && true
->false
Upvotes: 5
Reputation: 5654
Replace
if((121<x<=181) && (8<y<=51))
by
if((121 < x && x <= 181) && (8 < y && y <= 51))
Upvotes: 4