views:

481

answers:

2

Title more or less says it all. In response to a touchesBegan event, my UIViewController recolours itself and adds some subviews.

It never receives the touchesEnded. I guess because the added subviews are somehow intercepting the event. I tried calling resignFirstResponder on the subviews to no avail.

The code works fine when I don't add the child views and the touch events are called as normal.

Any ideas?

Thanks

EDIT: Bit of detail and how I fixed it.

Basically I had a master view with some subviews, when I touched the subview, the event would be passed through to the master view, however, on this event I was removing the subviews and adding new ones in their place. The fact that the touch originated on a subview which no longer existed meant that the rest of the touch was lost.

I fixed this by overriding hitTest:withEvent in my master view, to stop touches ever getting tested against the subviews

A: 

You're going to need pass the touch from the subview onto the superview using something like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];
}
Martin
the subviews don't receive the event either. If I add a subview to the place where the touchesBegan event occurred, neither the subview nor the superview receive touchesMoved/Cancelled/Ended
Sam
This passes the touch to the superCLASS, not the superVIEW. ;)
Pascal
+2  A: 

Did you try to set the userInteractionEnabled property to NO for the subview before adding it as a subview ?

yonel
no, this sounds promising, will try...
Sam