【发布时间】:2014-06-18 08:42:56
【问题描述】:
我正在开发扫雷游戏,我想在用户长按游戏板的图块时添加标志。 我已经实现了这段代码:
对于游戏板中的每个按钮:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressTap:)];
longPress.minimumPressDuration = 1.0f;
[self.button addGestureRecognizer:longPress];
在self中,方法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--;
}
}
当然 self 是我的 UIGestureRecognizerDelegate。 但是当我尝试长按某个磁贴时,应用程序崩溃并出现此错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer block]: unrecognized selector sent to instance 0x8cf2b00'
我该怎么办?我刚开始使用 Obj-C 编程,所以如果有人可以帮助我并解释我做错了什么,我将非常感激。
【问题讨论】:
标签: ios objective-c uibutton long-press