I am working on a Minesweeper game, I want to add a flag when the user long presses on the tile of the playing field. I have implemented this code:
For each button in the playing field:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressTap:)]; longPress.minimumPressDuration = 1.0f; [self.button addGestureRecognizer:longPress];
In self, the longPressTap method:
- (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 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 I'm my UIGestureRecognizerDelegate. But when I try to press the tile for a long time, the application crashes and throws this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer block]: unrecognized selector sent to instance 0x8cf2b00'
What should I do? I am at the very beginning of Obj-C programming, so if someone can help me and explain what I did wrong, I will be very grateful.
source share