Domanda

I'm trying to transition from my current view controller self to self.aVC using view controller containment using self.navigationController as the container. When I run the following code, the "children view controllers must have a common parent view controller" error pops up but the two NSLogs show the same parentViewController.

What seems to be the problem here? Any help is appreciated.

[self willMoveToParentViewController:nil];
[self.navigationController addChildViewController:self.aVC];
[self.aVC.view setFrame:self.bottomFrame];

NSLog(@"%@",self.parentViewController);
NSLog(@"%@",self.aVC.parentViewController);

//    __weak __block SBSomeVC *weakSelf = self;
[self transitionFromViewController:self toViewController:self.aVC duration:0.3 options:UIViewAnimationOptionTransitionNone animations:^{
    [self.aVC.view setFrame:self.view.bounds];
} completion:^(BOOL finished) {
    [self.aVC didMoveToParentViewController:self.navigationController];
    [self removeFromParentViewController];
}];
È stato utile?

Soluzione 2

To my understanding, -transitionFromViewController:toViewController:duration: must be called on a given view controller to transition between two child view controllers.

So, in your case, you should move that method call in the parent view controller class.

You should also ensure that both the view controllers you pass as arguments are already added as children view controllers of the parent one, or you'll keep getting the same error.

Reference: https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

Altri suggerimenti

The error:

Children view controllers must have a common parent view controller

tells you everything. Both view controllers that are taking part in the transition have to have the same parent. So you need to add both of them to the parent using the addChildViewController: method. Otherwise it will not work.

The transitionFromViewController:toViewController:duration method has to be called by the parent view controller. Not by the child.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top