Custom Unwind Segue for iOS 8 and iOS 9

后端 未结 2 1283
终归单人心
终归单人心 2021-02-09 20:52

My question is, how do I get the following custom unwind segue to work on a device with a version prior to iOS 9 as well as on a device running iOS 9?

I

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 21:20

    I slightly modified your code.
    I don't have to consider whether push or modal.
    It seems to work fine.

    - (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier
    {
        UIStoryboardSegue *segue;
        if ([fromViewController isKindOfClass:[MyViewController class]]) {
            segue = [[CustomSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController]; //Custom Unwind Segue
        }
        else {
            if ([super respondsToSelector:@selector(unwindForSegue:towardsViewController:)]) {
                [super unwindForSegue:segue towardsViewController:toViewController];
            }
            segue = [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
        }
    
        return segue;
    }
    

提交回复
热议问题