views:

142

answers:

2

Working with iPhone SDK 3.2 --

I have a complex custom UIControl that handles touches on the child controls. In certain cases, I want the parent UIControl to pass an event to the UIViewController, which will then take action outside the control. How do I do this cleanly? Thank you!

A: 

You can override hitTest:withEvent: in the UIControl and return nil when you determine that the touch should be handled by the parent.

progrmr
Clever approach, thanks. If this were Flash/ActionScript, I would have the UIViewController listen for a custom event from the parent UIControl; and I would dispatch this event in the UIControl when my conditions were met. That approach makes a lot of sense to me, too -- is it ever used in Objective C?
Elon
I've tried using touchesBegan:, touchesMoved:, etc in the VC but you only get touches that are not handled by any UIControl so that may or may not work for what you want.
progrmr
A: 

I ended up handling this with

[control addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];

in the UIViewController

and

[self sendActionsForControlEvents:UIControlEventValueChanged];

in the UIControl

Elon