I'm working on the Minesweeper game, I want to add the flag when user long tap on a tile of the gameboard. I've implemented this code:
For every button in gameboard:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressTap:)];
longPress.minimumPressDuration = 1.0f;
[self.button addGestureRecognizer:longPress];
In self, the method longPressTap:
- (void)longPressTap:(Tile *)sender {
if (sender.block.marking == MARKING_FLAGGED) {
// if already a flag I mark as a blank tile, with color defined for gameboard
sender.backgroundColor = UIColorFromRGB(0x067AB5);
sender.block.marking = MARKING_BLANK;
self.flagCount++;
}
else{
// if it's not a flag I mark as a flag and set the flag image for the tile
[sender setBackgroundImage:[UIImage imageNamed:IMAGE_NAME_FLAG] forState:UIControlStateNormal];
sender.block.marking = MARKING_FLAGGED;
self.flagCount--;
}
}
And of course self is my UIGestureRecognizerDelegate. But when I try to long press on a tile, the app crash and give this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer block]: unrecognized selector sent to instance 0x8cf2b00'
What should I do? I'm at the very beginning with Obj-C programming so if someone can help me and explain what I did wrong I'll be very grateful.