在我的iOS应用程序中,我有一个UIImageView,当我点击它时,会调用一个方法。
这是方法:
- (void)tapImagesLike:(UITapGestureRecognizer*)recognizer idOfTheImage:(NSInteger*) id_image{
//here i want to use the passed value id_image
}
我无法调用它并在输入中获取参数。
这是在单击UIImageView时调用该方法的代码:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImagesLike:idOfTheImage:x)];
singleTap.numberOfTapsRequired = 1;
likeImageImageview.userInteractionEnabled = YES;
[likeImageImageview setMultipleTouchEnabled:NO];
[likeImageImageview addGestureRecognizer:singleTap];
x是我想在输入方法时给出的NSInteger。
我该怎么办?
答案 0 :(得分:0)
只需为每个imageView
添加一个标记,并将该标记用作其ID。所以你不需要传递参数。并修改如下代码:
- (void)tapImagesLike:(UITapGestureRecognizer*)recognizer{
UIView *imageView = recognizer.view; //cast it to UIImageView if needed
//use imageView.tag as the id
}