Selecting Cells, Rows, Columns and Table Area

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example implements changing of table selection area. Firstly, table cell is selected, then multiple selection of column, rows, the whole table selection is executed, and after that the selection area is cleared. The development environment console also displays value of the last pressed cell, table column width value, the number of selected rows and columns.

Source Code

Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Creating a Simple Data Grid section):

-(void) executeExample{
    // Enable table cell selection
    [contr setCanSelect:YES];
    // Enable multiple selection
    [contr setMultiselect:YES];
};
// Handle table cell press event
- (void)gridView:(NuGridView *)gridView wasTouchedInCell:(NuGridCell *)cell {
    // Enter last pressed cell value if it is not header
    if(![[cell row] isHeader] & ![[cell column] isHeader])
    {
        NSLog(@"%@ %@", @"Last pressed cell value:", [[[gridView controller] lastTouchedCell] value]);
        ViewController *delegate = [contr delegate];
        // Get the object used to work with table and display column width
        NSInteger columnWidth = [delegate gridView:(NuGridView *)gridView widthForColumn:0];
        NSLog(@"%@ %d", @"Table column width:", columnWidth);
    }
}
- (void)gridView:(NuGridView *)gridView wasTouchedInRow:(NuGridRow *)row{
    // Select the specified table columns if the table does not have selected rows or columns
    if([[[gridView controller] selectedColumns] count] == 0
       & [[[gridView controller] selectedRows] count] == 0)
    {
        [[gridView controller] selectColumnByNumber:2];
        [[gridView controller] selectColumnByNumber:0];
        // Display the number of selected columns
        NSSet *set = [[gridView controller] selectedColumns];
        NSLog(@"%@ %d",@"Number of selected columns:", set.count);
        return;
    }
    if([[[gridView controller] selectedRows] count] == 0)
    {   // Deselect the specified columns
        [[gridView controller] deselectColumnByNumber:0];
        [[gridView controller] deselectColumnByNumber:2];
        // Select the specified table rows if the table does not have selected rows
        [[gridView controller] selectRowByNumber:2];
        [[gridView controller] selectRowByNumber:0];
        // Display the number of selected rows
        NSSet *set = [[gridView controller] selectedRows];
        NSLog(@"%@ %d",@"Number of selected rows:", set.count);
        return;
    }
    // Deselect the specified table rows
    [[gridView controller] deselectRowByNumber:0];
    [[gridView controller] deselectRowByNumber:2];
    // Select the whole table area
    [[gridView controller] selectAll];
}
- (void)gridView:(NuGridView *)gridView wasTouchedInColumn:(NuGridColumn *)column{
    // Clear selection area
    [[gridView controller] clearSelection];
}

Click any table cell. As a result, the cell is selected:

The development environment console displays value of pressed cell and table column width value:

Last pressed cell value: 4

Table column width: 80
 

Click table cell header. As a result, two table columns are selected:

The development environment console displays the number of selected columns:

Number of selected columns: 2


Press again table row header. After that two table rows are selected:

The development environment console displays the number of selected rows:

Number of selected rows: 2


Click again table rows header. As a result, the whole table is selected:

Then press any table column header. After that the table selection is cleared.

See also:

Examples of Component Use