Jack Thompson
Jack Thompson

Reputation: 41

iPhone UIControl and Subview

I currently have a UIControl, which has a number of subviews (image, label).

Unfortunately when I use addTarget etc. It doesn't detect touches on the subviews.

  [myCustomView addTarget:self action:@selector(touchedView:)
             forControlEvents:UIControlEventTouchUpInside];

Is it possible for the UIControl to detect touches on subviews or should i be approaching it differently.

Upvotes: 4

Views: 3644

Answers (3)

snod
snod

Reputation: 2443

Just note that all subviews of a UIControl which shouldn't receive touch events themselves must have userInteractionEnabled set to NO and not YES (which is the default).

So you must set this on all labels, images, etc.

I just ran into this and figured it out after a while :)

Upvotes: 23

Manjunath
Manjunath

Reputation: 4555

[myCustomView setUserInteractionEnabled:YES];

Upvotes: 0

just_another_coder
just_another_coder

Reputation: 73

Your method call is correct.

myCustomView should be the image or label being added.

Upvotes: 0

Related Questions