UITapGestureRecognizer selector, sender is the gesture, not the ui object

后端 未结 4 615
难免孤独
难免孤独 2021-01-31 07:47

I have a series of imageviews that I identify using their tag. I have added a single tap gesture to the images.

UITapGestureRecognizer *singleTap = [[UITapGest         


        
4条回答
  •  鱼传尺愫
    2021-01-31 08:31

    The only argument you can send through UITapGestureRecognizer selector is the UITapGestureRecognizer itself as following:

    Make sure to put ":" after the selector name like you previously did :

    UITapGestureRecognizer *singleTap = 
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectImage:)];
    

    Then add a parameter to selectImage so you can retrieve the View as following:

    -(void) selectImage:(UITapGestureRecognizer *)gestureRecognizer{
    
        //Get the View
        UIImageView *tableGridImage = (UIImageView*)gestureRecognizer.view;
    }
    

提交回复
热议问题