objective-c : custom segue transition between 2 viewControllers

84 Views Asked by At

I've inherit from NSStoryboardSegue in order to implement a custom transition between 2 VCs.

@interface MyReplaceSegue : NSStoryboardSegue

@end

@implementation MyReplaceSegue

-(void)perform {
    NSViewController *s = self.sourceController;
    NSViewController *d = self.destinationController;

    [s.view.window.contentViewController addChildViewController:d];
    
    [s.view.window.contentViewController transitionFromViewController:s toViewController:d options:NSViewControllerTransitionCrossfade completionHandler:^{
        [s removeFromParentViewController];
    }];
}

It works most of the time. However, there's one transition which bring the method transitionFromViewController to the following assertion/exception :

2020-10-05 21:55:23.643066+0300 0x26141    Default     0x2b33a              5098   0    myProc:
 (Foundation) *** Assertion failure in -[NSViewController 
transitionFromViewController:toViewController:options:completionHandler:], 
/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-
1671.60.109/Controllers/NSViewController.m:917

2020-10-05 21:55:23.645250+0300 0x26141    Error       0x0                  5098   0    myProc:
 (AppKit) [com.apple.AppKit:General] We must be the parent of fromViewController

I'm not sure I understand the description We must be the parent of fromViewController.. I've set the dest viewController to be child of the source viewController.

Perhaps anybody encountered such an exception ? I assume it relates to the nature of the source VC but I cannot figure out how ?

0

There are 0 best solutions below