Not receiving touchesEnded/Moved/Cancelled after adding subView

cocoa-touch, iphone, uitouch, uiview, uiviewcontroller

Solution

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

Problem

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

Original source