jeudi 4 septembre 2014

CGPath error when detecting user taps


Vote count:

0




I have an app that displays a target, with rings and hidden regions that give feedback to the user. The hidden regions are basically irregular 'pie slices.' When a user taps the target, code determines where the tap occurred and gives feedback to the user. The hidden pie slices are CGPaths. Everything works fine if the user taps inside the target. However, I am receiving an error if a user taps the screen OUT of the target area. Here is my toucesBegan method:



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

NSString *message = [[NSString alloc] init];

CGPoint tap = [[touches anyObject] locationInView:self];
[self addHitToTargetAt:tap];

for(int i=0; i<sizeof(regions); i++){
if(CGPathContainsPoint(regions[i], NULL, tap, NO)){ //error here if user taps outside of target
message = [suggestions objectForKey:[NSString stringWithFormat:@"%d", i]];
break;
}
}
[self.delegate setResultsLabelWith:message];
}


And the error (obviously I am trying to access something I don't own). It seems though, that the if statement would simply be false if the user taps outside of any region



ERROR: Thread 1:EXC_BAD_ACCESS (code=2, address=0x0)


Any suggestions? Thanks!



asked 55 secs ago







CGPath error when detecting user taps

Aucun commentaire:

Enregistrer un commentaire