Pre-populate search text

Setting the scene:
I’m using a vanilla PTDocumentController to display PDF files.In the upper right, I have the magnifying glass. Tapping on it makes the search bar pop up from the bottom.
This is great, it’s absolutely what I want.

Question:
How can I programmatically set the initial text that appears in that search bar?

We have our own search algorithm that presents a list of PDF documents that contain that search term. So when the user opens up one of those docs, then taps on the magnifying glass, I want the search bar to start off showing that initial search term that led them to the doc in the first place.

Hello,

The recommended way to do this would be to subclass the PTTextSearchViewController class by following the instructions here:
https://www.pdftron.com/documentation/ios/guides/tools/customization/#override-classes

Then in your subclass’ viewDidAppear() method you could call the findText() API with your search string as the parameter:

class MyTextSearchViewController: PTTextSearchViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
findText(“textToSearch”)
}
}

This will immediately perform the search with the specified text.

Please let us know how the above works for you and if you have any other questions. Thank you.

This is fantastic! Works like a champ, thank you!