-segueForUnwindingToViewController: fromViewController: identifier: not being called

前端 未结 4 1188
广开言路
广开言路 2020-12-29 23:28

I have created a custom segue that presents a view controller inside a container that is very similar with Apple\'s own modal view controllers (I\'ve implemented it as a UIV

4条回答
  •  一向
    一向 (楼主)
    2020-12-30 00:01

    If you're using a UINavigationController and your segue is calling pushViewController then in order to use a custom unwind segue you'll need to subclass UINavigationController and override - (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier.

    Say I have a custom unwind segue called CloseDoorSegue. My UINavigationController subclass implementation might look something like:

    - (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
    
    UIStoryboardSegue* theSegue;
    
    if ([identifier isEqualToString:@"CloseDoor"]) {
        theSegue = [CloseBookSegue segueWithIdentifier:identifier source:fromViewController destination:toViewController performHandler:^(void){}];
    } else {
        theSegue = [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
    }
    
    return theSegue;
    

    }

    Set your UINavigationController subclass as the navigation controller class in the storyboard. You should be good to go provided you have setup the Exit event correctly with "CloseDoor" as the identifier. Also be sure to call 'popViewControllerAnimated' in your unwind segue instead of dismiss to keep in line with UINavigationControllers push/pop mechanism.

提交回复
热议问题