Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - childViewController not receiving events

Newest Update: I created a brand new project that is built the exact same way as below. However, this test project actually works just fine even though it seems to be the same... One thing I've noticed is that the parent view controller in the broken version is receiving the -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event when clicking on the child view controller's view... In the working version, the child view controller receives the event as it should... It's as if the parent view is blocking the child view or something..?

Progress Update: Upon screwing around a bit I have found that it works fine when directly assigning a frame to the child view controllers. However, I have to create my project using autolayout so that is what I've done. For some reason, autolayout is causing the child view controller's view to be unresponsive...

At the moment I have a viewcontroller which has just 1 childviewcontroller. The childviewcontroller's view shows up just fine but I cannot interact with the childViewController at all. The childViewController has a couple of UIButtons but they do not respond to clicks.

I tried testing with this in both the parent and child viewcontrollers.

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"Touched!");
}

When clicking in the frame of the child view controller's view, this method responds in the parent view controller but not the child view controller.

The child view controller also works correctly when directly creating it and setting it as the root view controller in the app delegate.

The code I'm using in the parent view controller:

(void) viewDidLoad
{
    [super viewDidLoad];
    self.detailPageVC = [[GoalDetailsPageViewController alloc] init];
    [self.view addSubview:self.detailPageVC.view];
    [self addChildViewController:self.detailPageVC];
    [self.detailPageVC didMoveToParentViewController:self];
}

Thanks for helping out a rookie! :)

like image 871
Sethypie Avatar asked Jul 08 '13 17:07

Sethypie


2 Answers

the actual problem was in my GoalDetailsPageViewController. The issue was actually caused by trying to use autolayout within a uiscrollview... a tricky thing. Anyways, the original code I posted is fine, thanks.

like image 93
Sethypie Avatar answered Oct 13 '22 10:10

Sethypie


Well, I can only suggest the following:

  • Make sure the userInteractionEnabled property of your buttons and the child ViewController's view is set to YES.
  • Double check that your view is not 'hidden' nor has an alpha of 0.0.
  • Confirm the exclusiveTouch of your partent ViewController's view is not set to YES.

Hope this helps!

like image 20
LuisCien Avatar answered Oct 13 '22 09:10

LuisCien