Working with Button for Adding and Removing Regular Report Page Bookmark

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes working with a button for adding and removing a bookmark in regular report viewer view. After starting the example the following operations are executed:

The button for adding and removing a regular report page bookmark looks as follows:

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 view array
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;
        // Display number of current document bookmarks in the development environment console
        NSLog(@"Number of current document bookmarks: %d", [dataViewController bookmarksCount]);
        // Add bookmark
        [reportDataViewControllerBase toggleBookmark];
        // Display number of current document bookmarks after adding a bookmark in the development environment console
        NSLog(@"Number of bookmarks in current document after adding a bookmark: %d", [dataViewController bookmarksCount]);
        // Remove bookmark by specified index
        [dataViewController removeBookmarkWithIndex:0];
        // Display number of current document bookmarks after removing a bookmark in the development environment console
        NSLog(@"Number of current document bookmarks after removing a bookmark: %d", [dataViewController bookmarksCount]);
        // Go to page with specified index
        [dataViewController jumpToPage: 3];
        // Add the current page to bookmarks
        [dataViewController addBookmark];
        // Return to first document page
        [dataViewController jumpToPage: 0];
        // Get button for adding and removing bookmark on regular report page
        UIBarButtonItem *bookmarkButtonItem = [reportDataViewControllerBase bookmarkButtonItem];
        // Set object that executes operation on the button click
        [bookmarkButtonItem setTarget:self];
        // Assign method that is executed on the button click
        [bookmarkButtonItem setAction:@selector(barButtonAction)];
    }
}

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

// Executes operation on the button click
- (void) barButtonAction
{
    // 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 view
        if([controller isMemberOfClass:[MAProceduralReportDataViewController class]])
        {
            // Get sheet viewer view
            MAProceduralReportDataViewController *dataViewController =(MAProceduralReportDataViewController *)controller;
            // Parse all current document bookmarks of regular report in cycle
            for(int i = 0; i < [dataViewController bookmarksCount]; i++)
            {
                // Get bookmark
                Bookmark *bookmark = [dataViewController bookmarkAtIndex:i];
                // Check bookmark page number
                if([bookmark page] == 3)
                {
                    // Open bookmark
                    [dataViewController openBookmark:i];
                    break;
                }
            }
        }
    }
}

After executing the example the development environment console displays result of adding and removing the bookmark in the current document of regular report:

Number of bookmarks in the current document: 0

Number of bookmarks in the current document after adding a bookmark: 1

Number of bookmarks in the current document after removing a bookmark: 0

 

Identical result can be obtained if replace the strings in the executeExample method:

// Remove bookmark by specified index
[dataViewController removeBookmarkWithIndex:0];

with the following code:

// Remove bookmark
[reportDataViewControllerBase toggleBookmark];

Then press the button for adding and removing a bookmark of regular report page . As a result, the mobile device screen displays the regular report with the bookmark opened on the third page.

See also:

Examples of Component Use