PSPDFSearchViewController


@interface PSPDFSearchViewController
    : PSPDFBaseTableViewController <UISearchDisplayDelegate,
                                    UISearchBarDelegate,
                                    PSPDFTextSearchDelegate, PSPDFStyleable>

The search view controller allows text and annotation searching within the current document. It uses PSPDFTextView under the hood and updates its delegate as results are loaded.

Usually this is presented as a popover, but it also works modally.

  • The class of the table view cell that is used to represent a search result.

    This method can be overridden to return a different class. The returned class has to be a subclass of UITableViewCell and needs to conform to PSPDFSearchResultViewable.

    In order to properly layout the table view, any instance of the returned class needs to be sizeable with auto layout.

    Note

    This method has to return a single class. Making the return value of this method dynamically return different classes in any way results in undefined behavior.

    Declaration

    Objective-C

    + (nonnull Class<PSPDFSearchResultViewable>)resultCellClass;

    Swift

    class func resultCellClass() -> PSPDFSearchResultViewable.Type

    Return Value

    A class object of the class that should be used to represent a single search result in the table view.

  • The class of the table view section header that is used to represent the scope of the current result section.

    The method can be overridden to return a different class. The returned class has to be a subclass of UITableViewHeaderFooterView and needs to conform to PSPDFSearchScopeViewable.

    A scope currently is only represented in the UI if the search view controller’s searchVisiblePagesFirst returns YES.

    In order to properly layout the table view, any instance of the returned class needs to be sizeable with auto layout.

    Note

    This method has to return a single class. Making the return value of this method dynamically return different classes in any way results in undefined behavior.

    Declaration

    Objective-C

    + (nonnull Class<PSPDFSearchScopeViewable>)scopeHeaderClass;

    Swift

    class func scopeHeaderClass() -> PSPDFSearchScopeViewable.Type

    Return Value

    A class object of the class that should be used to represent the scope of the current section of results.

  • The class of the table view section footer that is used to represent the search status.

    The method can be overridden to return a different class. The returned class has to be a subclass of UITableViewHeaderFooterView and needs to conform to PSPDFSearchStatusViewable.

    A status currently is only represented in the UI if it is not idle (i.e. if the search has already been started).

    In order to properly layout the table view, any instance of the returned class needs to be sizeable with auto layout.

    Note

    This method has to return a single class. Making the return value of this method dynamically return different classes in any way results in undefined behavior.

    Declaration

    Objective-C

    + (nonnull Class<PSPDFSearchStatusViewable>)statusFooterClass;

    Swift

    class func statusFooterClass() -> PSPDFSearchStatusViewable.Type

    Return Value

    A class object of the class that should be used to represent the status of the current search in the table view.

  • Designated initializer.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithDocument:(nullable PSPDFDocument *)document;

    Swift

    init(document: PSPDFDocument?)
  • The current document.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) PSPDFDocument *document;

    Swift

    var document: PSPDFDocument? { get set }
  • The search view controller delegate.

    Declaration

    Objective-C

    @property (readwrite, nonatomic)
        id<PSPDFSearchViewControllerDelegate> _Nullable delegate;

    Swift

    @IBOutlet weak var delegate: PSPDFSearchViewControllerDelegate? { get set }
  • Current searchText. If set before showing the controller, keyboard will not be added.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *searchText;

    Swift

    var searchText: String? { get set }
  • Different behavior depending on size classes.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL showsCancelButton;

    Swift

    var showsCancelButton: Bool { get set }
  • Search bar for controller. - warning: You can change attributes (e.g. barStyle) but don’t change the searchBar delegate.

    Declaration

    Objective-C

    @property (readonly, nonatomic) UISearchBar *_Nonnull searchBar;

    Swift

    var searchBar: UnsafeMutablePointer
  • Current search status. KVO observable.

    Declaration

    Objective-C

    @property (readonly, nonatomic) PSPDFSearchStatus searchStatus;

    Swift

    var searchStatus: PSPDFSearchStatus { get }
  • Clears highlights when controller disappears. Defaults to NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL clearHighlightsWhenClosed;

    Swift

    var clearHighlightsWhenClosed: Bool { get set }
  • Defaults to 600. A too high number will be slow.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        NSUInteger maximumNumberOfSearchResultsDisplayed;

    Swift

    var maximumNumberOfSearchResultsDisplayed: UInt { get set }
  • Set to enable searching on the visible pages, then all. Defaults to NO. If not set, the natural page order is searched.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL searchVisiblePagesFirst;

    Swift

    var searchVisiblePagesFirst: Bool { get set }
  • Number of lines to show preview text. Defaults to 2.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) NSUInteger numberOfPreviewTextLines;

    Swift

    var numberOfPreviewTextLines: UInt { get set }
  • Searches the outline for the most matching entry, displays e.g. Section 100, Page 2 instead of just Page 2. Defaults to YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL useOutlineForPageNames;

    Swift

    var useOutlineForPageNames: Bool { get set }
  • The last search result is restored in viewWillAppear: if the document UID matches the last used one. This search result is only persisted in memory. Defaults to YES. - note: Needs to be set before the view controller is presented to have an effect.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL restoreLastSearchResult;

    Swift

    var restoreLastSearchResult: Bool { get set }
  • Will include annotations that have a matching type into the search results. (contents will be searched). Defaults to PSPDFAnnotationTypeAll&~PSPDFAnnotationTypeLink. - note: Requires the PSPDFFeatureMaskAnnotationEditing feature flag.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        PSPDFAnnotationType searchableAnnotationTypes;

    Swift

    var searchableAnnotationTypes: PSPDFAnnotationType { get set }
  • Determines the searchbar positioning. Defaults to PSPDFSearchBarPinningAuto.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFSearchBarPinning searchBarPinning;

    Swift

    var searchBarPinning: PSPDFSearchBarPinning { get set }
  • Internally used PSPDFTextSearch object. (is a copy of the PSPDFTextSearch class in document)

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) PSPDFTextSearch *textSearch;

    Swift

    var textSearch: PSPDFTextSearch? { get }
  • Call to force a search restart. Useful if the underlying content has changed.

    Declaration

    Objective-C

    - (void)restartSearch;

    Swift

    func restartSearch()
  • Called every time the text in the search bar changes.

    Declaration

    Objective-C

    - (void)filterContentForSearchText:(nonnull NSString *)searchText
                                 scope:(nullable NSString *)scope;

    Swift

    func filterContent(forSearchText searchText: String, scope: String?)
  • Will update the status and insert/reload/remove search rows

    Declaration

    Objective-C

    - (void)setSearchStatus:(PSPDFSearchStatus)searchStatus
                updateTable:(BOOL)updateTable;

    Swift

    func setSearchStatus(_ searchStatus: PSPDFSearchStatus, updateTable: Bool)
  • Returns the searchResult for a cell.

    Declaration

    Objective-C

    - (nonnull PSPDFSearchResult *)searchResultForIndexPath:
        (nonnull NSIndexPath *)indexPath;

    Swift

    func searchResult(for indexPath: IndexPath) -> PSPDFSearchResult
  • Will return a searchbar. Called during viewDidLoad. Use to customize the toolbar. This method does basic properties like tintColor, showsCancelButton and placeholder. After calling this, the delegate will be set to this class.

    Declaration

    Objective-C

    @property (readonly, nonatomic) UISearchBar *_Nonnull createSearchBar;

    Swift

    var createSearchBar: UnsafeMutablePointer
  • Currently loaded search results.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSArray<PSPDFSearchResult *> *_Nonnull searchResults;

    Swift

    var searchResults: [PSPDFSearchResult] { get }