Working with Regular Report Delegate

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes some methods of working with regular report delegate. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Regular Report section):

// Get regular report view
MAProceduralReportViewController *proceduralReportController = (MAProceduralReportViewController *)m_controller;
// Get regular report delegate
id<MAProceduralReportViewControllerDelegate> delegate = [proceduralReportController delegate];
// Display regular report title in the development environment console
if ([delegate respondsToSelector:@selector(reportTitle)]) {
    NSLog(@"Regular report title: %@",[delegate reportTitle]);
} else {
    NSLog(@"Regular report title is not specified");
}
// 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 *base = (MAProceduralReportDataViewControllerBase *)dataViewController;
        // Get document view
        UIWebView *pdfView = [base pdfView];
        // Get document borders
        CGRect frame = [pdfView frame];
        // Save top left corner coordinates of document border in delegate as array of bytes
        NSNumber *frameOriginX = [NSNumber numberWithInt:frame.origin.x];
        NSNumber *frameOriginY = [NSNumber numberWithInt:frame.origin.y];
        NSMutableDictionary *stateData = [NSMutableDictionary dictionary];
        [stateData setObject:frameOriginX forKey:@"frame.origin.x"];
        [stateData setObject:frameOriginY forKey:@"frame.origin.y"];
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:stateData];
        [delegate setState:data];
        // Set new values of top left corner coordinates of document border
        frame.origin.x = frame.origin.x + 30;
        frame.origin.y = frame.origin.y + 30;
        // Update regular report location
        [base updateViewWithFrame:frame];
        // Restore initial location of regular report after pause
        [self performSelector:@selector(restoreSettings:) withObject:[delegate state] afterDelay:5];
    }
}

I is also required to add the following method with its implementation in the ViewController class:

// Restores saved state of regular report
- (void) restoreSettings:(NSData *)data
{
    // 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 sheet viewer
        if([controller isMemberOfClass:[MAProceduralReportDataViewController class]]) {
            // Get sheet viewer view
            MAProceduralReportDataViewController *dataViewController =(MAProceduralReportDataViewController *)controller;
            // Get regular report viewer view
            MAProceduralReportDataViewControllerBase *base = (MAProceduralReportDataViewControllerBase *)dataViewController;
            // Get document view
            UIWebView *pdfView = [base pdfView];
            // Get document borders
            CGRect frame = [pdfView frame];
            // Retrieve regular report settings
            NSDictionary *dataState = [NSKeyedUnarchiver unarchiveObjectWithData:(NSData *)data];
            // Set top left corner coordinates of regular report border
            NSNumber *frameOriginX = [dataState valueForKey:@"frame.origin.x"];
            NSNumber *frameOriginY = [dataState valueForKey:@"frame.origin.y"];
            frame.origin.x = [frameOriginX intValue];
            frame.origin.y = [frameOriginY intValue];
            // Refresh regular report location
            [base updateViewWithFrame:frame];
        }
    }
}

 After executing the example the development environment console displays regular report title:

Regular report title: Procedural report

 

The mobile device screen also displays the regular report, for which new values of top left corner coordinates of document border are set:

The regular report is restored to its initial state in five seconds after starting the example:

See also:

Examples of Component Use