iOS Dev Nugget 51 Keeping Swipe to Go Back in iOS 7 With Custom Back Button


Need to run a code review on your codebase? Hire me

When using UINavigationController and pushing view controllers, you'll often want to use a custom back button by implementing your own custom view (usually a UIButton) and assigning it to the navigation item's leftBarButtonItem property. Or you might just want to keep the default back button and want to do something additional when user taps back, such as playing a sound effect by implementing -navigationController:animationControllerForOperation:fromViewController:toViewController: of UINavigationControllerDelegate. In iOS 7, you'll find that both approaches still work except that the default swipe right from left edge of screen gesture to go back stops working. All you need to do is the following to fix it:

UINavigationController* nc;
nc.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;

You don't have to implement any methods from the UIGestureRecognizerDelegate protocol.

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No


Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter


View archives of past issues