0
  1. There is a viewController here. In its addChildViewController function, I add a tableViewController as its child.
  2. Now, what we can see is the viewController's, but I want to show the tableViewController's tableView. I achieve this by:

    [viewController presentViewController:tableViewController animate:YES xxx:xxx]

  3. What I do in the 2nd step trigger some error:“Application tried to present modally an active controller.”

So the question is:

  1. If I want to show a view of the childViewController of a viewController, couldn't I use presentViewController function?

  2. If so, why?

  3. How could I solve the problem?

Thanks a lot for reading and answering. I've hunt for the reason for days.

Min Wang
  • 305
  • 4
  • 16
  • When you add a controller as a child, you also have to add that controller's view as a subview of the parent controller's view. You should not call `presentViewController:animated:`. You should read Apple's document, "Creating Custom Container View Controllers". – rdelmar Jun 07 '15 at 16:33
  • @rdelmar thx a lot ! i've read the document,and that do me a big favor! – Min Wang Jun 18 '15 at 03:25

1 Answers1

0

This is what gives you a clue for the answer "Application tried to present modally an active controller。"

There are two solutions:

1.Instead of using presentViewController, you should use addSubview like this:

[viewController.view addSubview:tableViewController.view];

2.Instead of using addChildViewController:

// [viewController addChildViewController:tableViewController];
[viewController.view presentViewController:tableViewController animate:YES completion:nil];
Bannings
  • 10,376
  • 7
  • 44
  • 54