Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes calculation of search results number by regular report. After starting the example the following operations are executed:
Regular report viewer view is retrieved.
A PDD document search delegate is created for regular report viewer with sending notifications on search events.
A new report viewer delegate is created with methods for getting information on search results.
The new report viewer delegate is subscribed for search delegate notifications.
Specified regular report string is searched by means of regular report viewer view.
The number of search results in regular report by means of created report viewer delegate is calculated.
The created report viewer delegate is used to execute operations required on finishing regular report search.
The number of search results in regular report by means of created report viewer delegate is retrieved.
It is required to add the following files to the Displaying of Regular Report base example:
ProceduralDelegateImplForSearch.h/.m. Report viewer delegate with methods for getting information on search results.
SearchDelegateWithNotifications.h/.m. Delegate for searching in PDF document with sending notifications on search events.
Executing the example requires to create a report viewer delegate class, which implements methods of the <ProceduralDelegate> protocol for getting information on search results, delegate class for searching in PDF document with sending notifications on search events, to add header files of these classes to source code of the ViewController class (see the Displaying of Regular Report section), and also to place the following code in the body of the executeExample method of the ViewController class:
// Get regular report object 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 sheet 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 PDF document search delegate SearchDelegateWithNotifications *searchDelegate = [[SearchDelegateWithNotifications alloc] init]; // Set search delegate in regular report viewer [reportDataViewControllerBase setSearchDelegate:searchDelegate]; // Create a report viewer delegate ProceduralDelegateImplForSearch *proceduralDelegateImpl = [[ProceduralDelegateImplForSearch alloc] init]; // Reset search results [proceduralDelegateImpl reset]; // Subscribe report viewer delegate for search delegate notifications [[NSNotificationCenter defaultCenter] addObserver:proceduralDelegateImpl selector:@selector(searchFinished) name:@"searchFinished" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:proceduralDelegateImpl selector:@selector(resultsCountChanged) name:@"resultsCountChanged" object:nil]; // Search specified string in regular report reportDataViewControllerBase.inSearching = YES; [reportDataViewControllerBase searchText: @"ia"]; // Call method that continues example execution after a pause // Execution of thread, in which the specified string is searched, should stop during the pause [self performSelector:@selector(continueExample:) withObject:proceduralDelegateImpl afterDelay:3]; } } }
It is also required to add the following method with its implementation in the ViewController class:
// Continues example execution - (void) continueExample: (ProceduralDelegateImplForSearch *) proceduralDelegateImpl { // Display number of search results in regular report in the development environment console NSLog(@"Number of matches with specified string: %d",[proceduralDelegateImpl searchResultsCount]); }
After executing the example the development environment console displays a message about stopping the thread, and also the number of regular report search results:
Search is finished
Number of matches with specified string: 6
See also: