Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of text search in regular report. After starting the example the following operations are executed:
Regular report sheet viewer view is retrieved.
Text search availability is checked.
A search delegate in PDF document is created.
The created delegate is set as a search delegate for regular report viewer.
It is determined whether regular report viewer is in search mode.
Specified page is searched in regular report.
Found string matches and search finish are handled by means of the created search delegate in PDF document.
Specified string search is stopped.
A search result view is created.
Document viewer delegate is set to present search results.
It is required to add the following file in the Displaying of Regular Report example:
SearchDelegate.h/.m. PDF document search delegate.
Executing the example requires to create a delegate class for search in PDF document, which implements operations that should be executed on finding specified text and search finish, and also to add class header file to source code of the ViewController class (see the displaying of Regular Report section). Then it is required to place the following code in the body of the executeExample method of the ViewController class:
// Get regular report view MAProceduralReportViewController *proceduralReportController = (MAProceduralReportViewController *)m_controller; // Get array of regular report views NSArray *dataViewControllers = [proceduralReportController dataViewControllers]; // Parse regular report views in cycle for( UIViewController *controller in dataViewControllers) { // Check if the current view is a regular report viewer if([controller isMemberOfClass:[MAProceduralReportDataViewController class]]) { // Get sheet viewer view MAProceduralReportDataViewController *dataViewController =(MAProceduralReportDataViewController *)controller; // Get regular report viewer view MAProceduralReportDataViewControllerBase *reportDataViewControllerBase = (MAProceduralReportDataViewControllerBase *)dataViewController; // Check if text search is available if([reportDataViewControllerBase isSearchAvaliable] == YES) { // Create a search delegate in PDF document SearchDelegate *searchDelegate = [[SearchDelegate alloc] init]; // Set search delegate in regular report viewer [reportDataViewControllerBase setSearchDelegate:searchDelegate]; // Determine whether viewer is in search mode [reportDataViewControllerBase setInSearching:YES]; // Search specified string in regular report [reportDataViewControllerBase searchText: @"Spain"]; } } }
After executing the example when the specified text is found, the development environment console displays a message with number of the regular report page containing the specified string:
Specified text is found on page 3
After search is finished the development environment console displays the appropriate message:
Text search is finished
Then it is required to place in the body of the executeExample method before the strings:
// Search specified string in regular report [reportDataViewControllerBase searchText: @"Spain"];
the following code:
// Stop search [reportDataViewControllerBase stopSearching];
After executing the updated example the search is stopped, that is why the message with number of the regular report page containing the specified string is not displayed in the development console.
Replace code strings in the executeExample method in the block
if([reportDataViewControllerBase isSearchAvaliable] == YES)
with the following code:
// Create a search result view PdfSearchResultsViewController *searchResultsController = [[PdfSearchResultsViewController alloc] init]; [searchResultsController setContentSizeForViewInPopover:CGSizeMake(300.0, 200.0)]; // Set document viewer delegate to present search results [searchResultsController setDelegate:dataViewController]; // Create a popup window UINavigationController *navController =[[[UINavigationController alloc] initWithRootViewController: searchResultsController] autorelease]; UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:navController]; popoverController.delegate = dataViewController; // Set regular report viewer search delegate [reportDataViewControllerBase setSearchDelegate:searchResultsController]; // Determine whether viewer is in search mode [reportDataViewControllerBase setInSearching:YES]; // Search specified string in regular report [reportDataViewControllerBase searchText: @"Togo"]; // Display popup window [popoverController presentPopoverFromRect:CGRectMake(100, 100, 1, 1) inView:[dataViewController pdfView].scrollView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
After executing the example the mobile device screen displays the regular report, which displays search result view with numbers of the pages, which contain matching searched text.
See also: