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.

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.


The recommended way to do this would be to subclass the PTTextSearchViewController class by following the instructions here:

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) {

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!