views:

149

answers:

2

I have a custom tablecell with an embedded MapView showing a small area. When the user selects the cell, I want to push a new view with a larger mapview and some more information, like distance from where you are, option of what map-type etc.

If I leave a small margin around my mapview, the user can click in that margin to select the cell, but how can I make the cell selected if they click inside the mapview?

regards,
-Vegar

+1  A: 

Try set MapView's userIteractionEnabled property to NO

Vladimir
That will just remove the events from the event queue. He needs to intercept them and let the parent view handle them.
willcodejavaforfood
It should work if he doesn't need to interact with MKMapView
Vladimir
I thought that when you disabled userInterActionEnabled it is like the touch NEVER happened at all?
willcodejavaforfood
Then view will not handle touches and let parent view handle it instead. (at least I think it must do so)
Vladimir
@vladimir - OK that would be an easy solution :)
willcodejavaforfood
Easy, but does it work? Nope ;-)
Vegar
@Vegar - Well at least it was so easy that it was worth trying before my more cumbersome solution :)
willcodejavaforfood
It should have worked, though. Reading the help for hitTest:withEvent, I found this line: "This method ignores views that are hidden, that have disabled user interaction, or have an alpha level less than 0.1." According to that, my mapview, with disabled user interaction, should be ignored, bit it's not... :-/
Vegar
I can confirm that this does indeed work! I have an MKMapView inside of a TableCellView. Setting this property now has the `didSelectRowAtIndexPath` event getting fired so I can handle touches of the embedded map.
Rob S.
+3  A: 

I think you need to override the hitTest method inherited from UIView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

This method traverses the view hierarchy by sending the pointInside:withEvent: message to each subview to determine which subview should receive a touch event. If pointInside:withEvent: returns YES, then the subview’s hierarchy is traversed; otherwise, its branch of the view hierarchy is ignored. You rarely need to invoke this method, but you might override it to hide touch events from subviews.

willcodejavaforfood
That's it. I implemented this method on my custom cell, and simply return self. Thanks!
Vegar