Working with Persisted Keys

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes some methods of working with persisted keys of table rows and columns. 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 Express Report section):

// Get array of data view controllers
NSArray *controllers =[m_controller dataViewControllers];
// Parse data view controllers in cycle
for(NSObject *controller in controllers)
{
    // Check if the current controller is a table data view controller
    if([controller isMemberOfClass:[MAGridDataViewController class]])
    {
        // Get table data view controller object
        MAGridDataViewController *gridController = (MAGridDataViewController *)controller;
        // Get table data source
        GridDataViewDatasource *grid = [gridController gridDatasource];
        // Get row persisted key
        MAGridDataSourcePersistentKey *rowPersistentKey = [grid rowPersistentKeyByNumber:1];
        // Get column persisted key
        MAGridDataSourcePersistentKey *columnPersistentKey = [grid columnPersistentKeyByNumber:1];
        // Get copy of column persisted key
        id<MAGridDataSourcePersistentKeyProtocol> persistentKey = [columnPersistentKey copyWithZone:[columnPersistentKey zone]];
        // Merge copy of column persisted key with row persisted key
        [persistentKey joinWith:rowPersistentKey];
        // Call cell selection method
        [self setSelectionForKey:persistentKey];
        break;
    }
}

Then it is required to add the following method with its implementation in the ViewController class:

// Selects table cell
-(void) setSelectionForKey: (id&lt;MAGridDataSourcePersistentKeyProtocol&gt;)key
{
    // Get array of data view controllers
    NSArray *controllers =[m_controller dataViewControllers];
    // Parse data view controllers in cycle
    for(NSObject *controller in controllers)
    {
        // Check if the current controller is a table data view controller
        if([controller isMemberOfClass:[MAGridDataViewController class]])
        {
            // Get table data view controller object
            MAGridDataViewController *gridController = (MAGridDataViewController *)controller;
            // Get table data source
            GridDataViewDatasource *grid = [gridController gridDatasource];
            // Get controller view
            UIView *view = [gridController view];
            // Get array of subviews
            NSArray *subviews = [view subviews];
            // Parse subviews in cycle
            for(NSObject *subview in subviews)
            {
                // Check if the current view is a table view
                if([subview isMemberOfClass:[NuGridView class]])
                {
                    // Get table view object
                    NuGridView *gView = (NuGridView *)subview;
                    // Get number of table columns
                    int columnCount = [grid gridViewColumnCount:gView];
                    // Get number of table rows
                    int rowCount = [grid gridViewRowCount:gView];
                    // Parse table rows in cycle
                    for(int i = 0; i &lt; rowCount; i++)
                    {
                        // Parse table columns in cycle
                        for(int j = 0; j &lt; columnCount; j++)
                        {
                            // Get row persisted key
                            MAGridDataSourcePersistentKey *rowPersistentKey = [grid rowPersistentKeyByNumber:i];
                            // Get column persisted key
                            MAGridDataSourcePersistentKey *columnPersistentKey = [grid columnPersistentKeyByNumber:j];
                            // Get copy of column persisted key
                            id&lt;MAGridDataSourcePersistentKeyProtocol&gt; persistentKey = [columnPersistentKey copyWithZone:[columnPersistentKey zone]];
                            // Merge copy of column persisted key with row persisted key
                            [persistentKey joinWith:rowPersistentKey];
                            // Check if obtained persisted key is equal to specified key
                            if([persistentKey isEqual:key])
                            {
                                // Select cell and finish method execution
                                [[gView controller] selectAreaFromRow:[gView rowWithNumber:i] column:[gView columnWithNumber:j] toRow:[gView rowWithNumber:i] column:[gView columnWithNumber:j]];
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
}

After executing the example the mobile device screen displays the express report containing a table, in which one of cells is selected:

See also:

Examples of Component Use