Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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!

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];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top