Working with Controller for Viewing Sheet from Regular Report Sheet Set

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes working with a controller for viewing sheets from corresponding regular report sheet set. 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):

// Create a regular report
SPPLProceduralReport2 proceduralReport2 = PPLProceduralReport2::proceduralReport(m_proceduralReportDescriptor);
// Create a regular report controller
MAProceduralReport2ViewController *controller = (MAProceduralReport2ViewController *)[MAProceduralReportViewControllerFactory createReport: proceduralReport2];
// Get data source
id<MAProceduralReportViewControllerDelegateExt> dataSource = (id<MAProceduralReportViewControllerDelegateExt>)[controller delegate];
// Create a controller for viewing regular report sheets from corresponding sheet sets
MAProceduralReportExtDataViewController *extDataViewController = [[MAProceduralReportExtDataViewController alloc] initWithDataSource: dataSource];
// Set sheet index in corresponding set
int workSheetIndex = 0;
// Get number of sheet sets
int worksheetSetsCount = [dataSource worksheetSetsCountInProceduralReportController: extDataViewController];
NSLog(@"Number of sheet sets: %d", worksheetSetsCount);
// Get active sheet set index
NSNumber *activeWorksheetSetIndex = [NSNumber numberWithInt: [dataSource starupWorksheetSetIdInProceduralReportController: extDataViewController]];
if([activeWorksheetSetIndex intValue] < 0) {
    // Set active sheet set index
    [extDataViewController setWorksheetSetIndex: 0];
    activeWorksheetSetIndex = [NSNumber numberWithInt: [extDataViewController worksheetSetIndex]];
    // Set active sheet set key
    [extDataViewController setWorksheetSetKey: [NSNumber numberWithInt: 2]];
}
NSLog(@"Regular report active sheet set index: %d", [activeWorksheetSetIndex intValue]);
// Get number of sheets in specified sheet set
int worksheetsCount = [dataSource proceduralReportController: extDataViewController worksheetsCountForWorksheetSet: activeWorksheetSetIndex];
NSLog(@"Number of sheets in specified sheet set: %d", worksheetsCount);
// Get sheet set title
NSString *worksheetSetTitle = [dataSource proceduralReportController: extDataViewController reportTitleForWorksheetSet: activeWorksheetSetIndex];
NSLog(@"Sheet set title: %@", worksheetSetTitle);
// Get sheet set identifier
NSNumber *workseetSetId = (NSNumber *)[dataSource proceduralReportController: extDataViewController worksheetSetIdAtIndex: [activeWorksheetSetIndex intValue]];
NSLog(@"Sheet set identifier: %d", [workseetSetId intValue]);
// Get first sheet name in specified set
NSString *name = [dataSource proceduralReportController:extDataViewController
worksheetSet: activeWorksheetSetIndex workSheetNameAtIndex: workSheetIndex];
NSLog(@"Regular report sheet name: %@", name);
// Get sheet key
NInteger key = [dataSource proceduralReportController: extDataViewController worksheetSet:activeWorksheetSetIndex workSheetKeyAtIndex: workSheetIndex];
NSLog(@"Regular report sheet key: %d", key);
// Get full path to sheet
NSString *fullPath = [dataSource proceduralReportController:extDataViewController worksheetSet:activeWorksheetSetIndex worksheetFullpathAtIndex: workSheetIndex];
NSLog(@"Full path to regular report sheet: %@", fullPath);
// Get file extension with regular report sheet
NSString *ext = [dataSource proceduralReportController: extDataViewController worksheetSet: activeWorksheetSetIndex worksheetExtAtIndex: workSheetIndex];
NSLog(@"File extension with regular report sheet: %@", ext);
BOOL isVisible = [dataSource proceduralReportController: extDataViewController worksheetSet:activeWorksheetSetIndex isWorksheetVisibleAtIndex: workSheetIndex];
NSLog(@"Whether regular report sheet is displayed: %d", isVisible);
// Display controller view
[self showViewControllerInFullScreen: extDataViewController];
// Create custom data
NSMutableData *data = [[NSMutableData new] autorelease];
NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:data] autorelease];
// Set current sheet index
int currentDocumentIndex = 1;
[archiver encodeObject:[NSNumber numberWithInt: currentDocumentIndex] forKey:@"CURRENT_DOCUMENT_INDEX"];
[archiver finishEncoding];
// Save settings
[dataSource proceduralReportController: extDataViewController setState: data];
// Get custom settings for regular report
NSData *state = [dataSource stateForProceduralReportController: extDataViewController];
if (state.length > 0) {
    NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:state] autorelease];
    if (NSNumber *docIndex = [unarchiver decodeObjectForKey:@"CURRENT_DOCUMENT_INDEX"]) {
        // Get current sheet index
        int currentDocumentIndex = [docIndex intValue];
        NSLog(@"Current sheet index in regular report: %d", currentDocumentIndex);
    }
}

After executing the example the mobile device screen displays a sheet with the 0 index and the 2 key in regular report. Information about this sheet and the sheet set is displayed in the development environment console.

Regular report active sheet set index: 0

Number of sheets in specified sheet set: 1

Sheet set title: Title

Sheet set identifier: 0

Regular report sheet name: Profile

Regular report sheet key: 1

Full path to regular report sheet: /Users/sea/Library/Application Support/iPhone Simulator/7.1/Applications/FF74E776-7B3C-4D6B-9132-912743B93C5E/Documents/repositories/nrspo-121.prognozcloud.ru:dev8:mobile/OBJECTS/REP_COMPANY_PROFILE_MOBILE/0-1.pdf

File extension with regular report sheet: pdf

Whether regular report sheet is displayed: 1

Current sheet index in regular report: 1

See also:

Example of Component Use