1

How can we interact with Parent UIViewController (having buttons) blocked by Child UIViewController. Apparently the touch events aren't going through the Child NIBs. (User Interaction Enabled)

Note: I'm loading both default and custom NIBs, (using initWithNibName: method).

Thanks.

2 Answers2

0

All actions should pass through the children to reach parent unless you set the child views userInteractionEnabled property to NO.

Therefore you need to :

[childController.view setUserInteractionEnabled:YES];
Ugur Kumru
  • 986
  • 6
  • 9
  • I've added this line under viewDidLoad both to parent as well as child. [self.view setUserInteractionEnabled:YES]; Besides this, I've checked the checkbox that says User Interaction Enabled inside both NIB files, but still not success. –  Jan 27 '12 at 16:32
  • Of course parent should enable userInteraction too to let the children enable user interaction. IF still no success some of the views inside your children may be blocking your interaction with the whole view, for example an image view with no interaction should block all the clicks on top of it and would not deliver any action to the parent – Ugur Kumru Jan 27 '12 at 16:47
  • Sorry I got your question in revers you mean that child is blocking parent's touches. This topic has the answer, basically what you need to do is to have a delegate to sendAll events coming to the child views.http://stackoverflow.com/questions/2003201/observing-pinch-multi-touch-gestures-in-a-uitableview/2003781#2003781 – Ugur Kumru Jan 27 '12 at 17:15
  • my bad... thanks for the catch... I'm looking at the answer but seems beyond my little knowledge and I see bunch of code chunks, can you please copy/paste for me what code should I put inside my Parent.m or Child.m. Thanks again. –  Jan 27 '12 at 17:21
  • What you need to do is you need to creat first and second chunks as new files as it says in the post which are EventInterceptWindow.h and EventInterceptWindow.m. Than in the interface builder you need to change the class type of your window to EventInterceptWindow.m. Than you need to set EventInterceptDelegate to which viewController you want to get the events. And use third chunk to figure out how to benefit from the delegate. – Ugur Kumru Jan 27 '12 at 17:26
  • I've created new class file EventInterceptWindow, changed the Window type in my AppDelegate.h, Added the delegate method with both returns as YES and NO to parent.m (tested with child.m also), but still the parent button not getting clicked, though NSLog statements inside delegate method are appearing and two times. [link to example project after the update](http://muizz.com/Test2.zip). Thanks Ugur for your continued support. –  Jan 27 '12 at 17:55
  • It is called because you have 2 views in your parent 1 is button other one is it's own view. Put this in the beginning of interceptEvent NSSet *touches = [event allTouches]; UITouch *oneTouch = [touches anyObject]; UIView *touchView = [oneTouch view]; Than you can check to see if touchView==parent.view or touchView==button.view e.g There should be a better way to solve this but this solves your problem for now. I believe putting controllers inside each other is not that good solutions before iOS 5 I would prefer putting views inside each other. – Ugur Kumru Jan 27 '12 at 18:12
0

This worked for me. UIViewController Containment

Thanks for comments by the support community.

http://www.youtube.com/watch?v=DzedmcFlm1c