添加UITapGestureRecognizer时UIImageView崩溃

时间:2012-10-02 18:36:30

标签: ios uiimageview gesture uicontrol uitapgesturerecognizer

@interface OOTRotaryWheel : UIControl


@property (weak) id <OOTRotaryProtocol> delegate;
@property (nonatomic, strong) UIView *container;
@property int numberOfSections;
@property CGAffineTransform startTransform;
@property (nonatomic, strong) NSMutableArray *sectors;
@property int currentSector;
@property (nonatomic, retain) UIImageView *mask;

- (id) initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber;
- (void)rotate;
- (void) buildSectorsEven;
- (void) buildSectorsOdd;

@end

在我的.m文件中

我的初始化方法

mask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 58, 58)];
mask.image =[UIImage imageNamed:@"centerButton.png"];
mask.center = self.center;
mask.center = CGPointMake(mask.center.x, mask.center.y+3);
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonPressedDown:)];
[mask addGestureRecognizer:singleTap];
[mask setMultipleTouchEnabled:YES];
[mask setUserInteractionEnabled:YES];



-(IBAction)buttonPressedDown
{
    //Connect this IBAction to touchDown
    mask.alpha = 0.5f;
    NSLog(@"tapping the center of the earth");
}

当我点按图片时,它会以此消息崩溃

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OOTRotaryWheel buttonPressedDown:]: unrecognized selector sent to instance 0x71724e0'
*** First throw call stack:

我以编程方式绘制了UI,因此Interface Builder中没有UI元素。我的用户界面是一个故事板,但它是空的。

1 个答案:

答案 0 :(得分:2)

你在buttonPressedDown的实现中忘记了冒号:要么删除singleTap定义的action参数中的冒号,要么将冒号和参数添加到实现中。