how to get the tag of the UIImageView I'm tapping?

前端 未结 3 1368
傲寒
傲寒 2020-12-16 05:29

i have several UIImageView, each of them has a tag; and I have an array of Images, what i want to do is: when user tap one of the UIImageView, the app give back the certain

3条回答
  •  执笔经年
    2020-12-16 05:56

    At the risk of making a recommendation without seeing the full picture of your app, why not use a custom UIButton instead of UIImageViews for this? With a UIButton you can setup an action and pass the sender id, from which you can easily access your tags and pull the data from your array.

    OR if you really want to use the above code and your know for a fact the - (void)findOutTheTag:(id)sender method is being called, all your have to do is:

    - (void)findOutTheTag:(id)sender {
        switch (((UIGestureRecognizer *)sender).view.tag)      
    {
        case kTag1:
        //...
        case kTag2:
        //...
      }
    }
    

提交回复
热议问题