Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: delegate's methods of the subclass of NavigationStackController are not called #259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

takehilo
Copy link

As shown below, an instance of NavigationDelegate is set to delegate property in a subclass of NavigationStackController.

ExampleNavigationStackController: NavigationStackController {
  private let navigationDelegate: NavigationDelegate

  public override func viewDidLoad() {
    super.viewDidLoad()
    delegate = navigationDelegate
  }
}

class NavigationDelegate: NSObject, UINavigationControllerDelegate {
  func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
    // ... not called
  }

  func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
    // ... called
  }
}

However, navigationController(_:willShow:animated:) is not called, while navigationController(_:didShow:animated:) is called.

In the viewDidLoad method of NavigationStackController, an instance of PathDelegate is assigned to delegate property. At this point, an implementation check using responds(to:) is performed. However, since NavigationDelegate has not yet been set, navigationController(_:willShow:animated:) is determined to be unimplemented.

To address this, I added the missing methods to responds(to:).

@acosmicflamingo
Copy link
Contributor

acosmicflamingo commented Feb 12, 2025

This fixes interactive pop animation issues for my own UINavigationController usage. Nice!

@stephencelis
Copy link
Member

@takehilo Thanks for looking into this! I was wondering if it's possible to add a test case that would have previously failed? The case studies suite has a bunch of tests you could look at for inspiration.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants