我想要实现的是:当我点击特定的UI ImageView时,UITapGesture会将一个字符串传递给tap方法. 我的代码如下:想象一下我已经有了一个UIImageView对象,当我点击这个图像时,它会打个电话, UITapG
          我的代码如下:想象一下我已经有了一个UIImageView对象,当我点击这个图像时,它会打个电话,
UITapGestureRecognizer *tapFirstGuy = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(makeCallToThisPerson:@"1234567")];
[imageViewOne addGestureRecognizer:tapFirstGuy];
- (void)makeCallToThisPerson:(NSString *)phoneNumber
{
    NSString *phoneNum = [NSString stringWithFormat:@"tel:%@", phoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNum]];
} 
 但是,我收到以下编译错误:@selector(makeCallToThisPerson:@“1234567”);
我无法弄清楚发生了什么.为什么我不能将字符串传递给私有方法?
该操作应该只是一个方法的选择器,该方法的签名必须是“采用单个id参数并返回void的方法”. id参数将(通常)是发送消息的对象.目标(操作发送到的对象)可以使用sender参数在需要时提取其他信息,但需要提供其他信息.它不是免费提供的.
也就是说,您的ImageView子类可能具有以下方法:
- (void)setPhoneNumber:(NSString *)phoneNumber; // set a phoneNumber property
- (void)prepareToBeTapped 
{
    UITapGestureRecognizer *tapFirstGuy = [[UITapGestureRecognizer alloc]
        initWithTarget:self action:@selector(makeCallToThisPerson:)];
    [self addGestureRecognizer:tapFirstGuy];
}
- (void)makeCallToThisPerson:(id)sender
{
    NSString *phoneURL = [NSString stringWithFormat:@"tel:%@", phoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneURL]];
} 
 也就是说,这不是行动,甚至不知道电话号码的UITapGestureRecognizer.目标必须以其他方式知道(或能够获得)电话号码,或者将其作为可设置的属性携带.
