pkluz / PKRevealController

PKRevealController is a delightful view controller container for iOS, enabling you to present multiple controllers on top of one another.
Other
3.85k stars 659 forks source link

PKRevealController doesn't play well with unwind segues #211

Open banaslee opened 10 years ago

banaslee commented 10 years ago

I had a problem on iOS 8 when the view controller chosen to start querying for a unwind action handler was a PKRevealController.

PKRevealController is unable to provide the right handler from its hierarchy and the action is left unhandled.

My solution was to override - viewControllerForUnwindSegueAction:fromViewController:withSender: like this:

- (UIViewController *)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
    NSArray *children = @[self.frontViewController];
    if (self.leftViewController) {
        children = [children arrayByAddingObject:self.leftViewController];
    }
    if (self.rightViewController) {
        children = [children arrayByAddingObject:self.rightViewController];
    }

    UIViewController *foundViewController;

    for (UIViewController *childViewController in children) {
        foundViewController = [childViewController viewControllerForUnwindSegueAction:action
                                                                   fromViewController:fromViewController
                                                                           withSender:sender];

        if (foundViewController) {
            break;
        }
    }

    if (!foundViewController) {
        foundViewController = [super viewControllerForUnwindSegueAction:action
                                                     fromViewController:fromViewController
                                                             withSender:sender];
    }

    return foundViewController;
}

I'm not able to do a pull request right now. I can only provide with this code for now.