Skip to content

Intercept Back Button Call in UINavigationController? #17

@Ben-G

Description

@Ben-G

Problem: When using ReSwiftRouter we want every view controller change to be reflected by a route update. This means we need to be notified when UIKit's container view controllers trigger VCs to be presented or hidden.

For UITabBarController we can implement delegate methods to intercept view controller changes and allow the router to change view controllers instead of the controller handling the changes directly.

For the back button of UINavigationController there's no comparable solution. Right now I'm using a workaround that I'm not very happy with: https://github.com/ReSwift/GitHubBrowserExample/blob/master/SwiftFlowGitHubBrowser/ViewControllers/RepositoryDetailViewController.swift#L37-L41

When a VC disappears, I check if the current route is still the one of the current VC. If that's the case, we know that the VC was dismissed without the route being updated; in response I update the route manually.

Any suggestions on how to intercept back button taps more directly are welcome. Ideally this would not involve replacing bar button items, or any other larger modifications of the UINavigationController.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions