Cancel search bar programmatically

I’m using the iOS SDK and trying to find a solution to my scenario.

  1. I’m overriding “toolManager(_ toolManager: PTToolManager, shouldShowMenu menuController: UIMenuController, forAnnotation annotation: PTAnnot?, onPageNumber pageNumber: UInt) → Bool” so that I can add a custom UIMenuItem.

  2. When the user taps on that custom menu item, my app navigates to another view controller of the app. (starting with “self.navigationController?.popViewController”).

That works perfect in most situations…UNLESS the user has the search bar open/active. If it’s open, and they then long press to show the menu and tap on my button, my UI is hosed until I relaunch.

What I have tried:

A - I tried calling self.closeDocument which appeared to work once, but not the second time. i.e. If the user goes back to the viewer and triggers that button again, self.closeDocument closes the document but doesn’t reliably let me navigate away.

B. I tried to hack my way through the subviews, searching for the “Done” button on the search bar and programmatically tapping it. This works! Terrifying, but it works. Except it has the same issue as C…

C. Right now I’m simply calling self.textSearchViewController.dismiss and navigating via it’s completion block. This also works, and is less terrifying than B. But…

B and C both insist on leaving that UIMenuController visible. I’m forced to repeatedly call UIMenuController.shared.hideMenu before I finally convince the thing that it should genuinely not be showing. Without that, I am in a situation where the pdf viewer is gone, I’m on a totally different view controller, but I still have that little popup menu offering to let me search the doc.

So…is there a cleaner way to handle this than my option C? I basically just want a programatic way to “cancel” that search bar before I navigate away.

Any help is greatly appreciated, thanks!

Hi,

Thank you for getting in touch with us about this.
Can you share a bit more information about your app’s workflow? Are you using a PTDocumentController or a PTPDFViewCtrl directly?

We don’t currently have a way to dismiss the search view programmatically but it is something we can look at implementing.