Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TouchUpInside on UIView with children

Tags:

I may be missing something here, but...

I have a UIView with a few children (a couple of UILabel's and UIImageView). I need to catch an event when the user clicks (taps) anywhere within the parent UIView - visible part of the UIView or any of its children).

What's the best way of doing this?

like image 529
Aleks G Avatar asked May 23 '12 22:05

Aleks G


1 Answers

You can change the UIView's class in the Identity Inspector ... make it UIControl and then you can add an event for UITouchUpInside for your view - to catch the taps on it.

Good luck!

EDIT: here's a step-by-step with screenshots:

The view... Original view - of type UIView

... of course, no events. UIView has no events you can use

Go back and change UIView with UIControl and... Change UIView to UIControl

Ta-daa! Events! UIControl allows you to use events

Hook a method to the UITouchUpInside event Add event for UITouchUpInside

This is how it should look like in the interface file The interface of the method

This is how it should look like in the implementation file (you can, of course, replace the logging with anything you want) The implementation of the method

like image 53
DarkByte Avatar answered Oct 04 '22 16:10

DarkByte