iOS - childViewController not receiving events
Asked Answered
N

3

7

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! :)

Noisemaker answered 8/7, 2013 at 17:44 Comment(5)
How do you define detailPageVC?Infighting
Not sure what you mean by define, sorry. @property GoalDetailsPageViewController *detailPageVC; ^Is this what you are looking for?Noisemaker
Yes, is that the full line?Infighting
Ya, that's the full line in my GoalPageViewController header file.Noisemaker
Thanks for using 'touchesBegan:withEvent:' to detect which view controller detected the event.Ogdon
N
3

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.

Noisemaker answered 7/8, 2013 at 23:29 Comment(0)
L
1

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!

Lodging answered 8/7, 2013 at 19:57 Comment(1)
setting userInteractionEnabled to true in my storyboard did the trick.Insnare
G
-1

My solution:

- (void) displayContentController: (UIViewController*) content{
[content.view setFrame:recorderView.bounds];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:content];
childNavController.toolbarHidden = NO;
childNavController.view.frame = content.view.frame;
[self addChildViewController:childNavController];
[recorderView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];
}
Gilgai answered 9/7, 2016 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.