Working with Table Selection Area

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example displays the following in the development environment console:

A new selected area is also created based on the existing one, and background color of its parent table is changed, selection area resize elements are displayed, if they were hidden or are hidden if they were displayed.

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 selection
    [contr setCanSelect:YES];
    // Disable changing of selection on data source refresh
    if([contr keepSelectionByIndex] == NO){
        [contr setKeepSelectionByIndex:YES];
    }
};
// Handle table selection area change event
- (void)gridViewSelectionChanged:(NuGridView *)gridView{
    // Get selected table area
    NuGridSelectionArea *selectionArea = [gridView selectionArea];
    // Get object used to work with selected table area
    NuGridController *delegate = [selectionArea delegate];
    // Display size and position of selected table area
    CGFloat frameWidth = [selectionArea originFrame].size.width;
    CGFloat frameHeight = [selectionArea originFrame].size.height;
    NSLog(@"%@ (%f, %f)", @"Size of selected table area:", frameWidth, frameHeight);
    CGPoint tPoint = [selectionArea initialTouchPoint];
    NSLog(@"%@ (%f, %f)", @"Position of selected table area:", [selectionArea actualizedRect].origin.x, [selectionArea actualizedRect].origin.y);
    // Display whether selection area is empty
    NSLog(@"%@ %hhd", @"Selection area is empty:", [selectionArea isEmpty]);
    // Dsiplay whether selected area is being changed at the moment
    NSLog(@"%@ %hhd", @"Selected area is being changed at the moment:", [selectionArea selecting]);
    // Create a new selected area based on the existing one
    NuGridSelectionArea *newSelArea = [NuGridSelectionArea createSelectionAreaForGrid:gridView withDelegate:delegate];
    // Change parent table background color of created selected area
    [[newSelArea parentGrid] setBackgroundColor:[UIColor grayColor]];
    // Display the number of selected elements
    NSLog(@"%@ %d", @"Number of selected elements:", [selectionArea elementNumber]);
    // Display selection area type
    NSString *selType = @"Selection area type: ";
    switch ([selectionArea type]) {
        case NuAreaTypeNone:
            selType = [selType stringByAppendingString:(NSString *)@"area is missing"];
            break;
        case NuAreaTypeRow:
            selType = [selType stringByAppendingString:(NSString *)@"row is selected"];
            break;
        case NuAreaTypeColumn:
            selType = [selType stringByAppendingString:(NSString *)@"column is selected"];
            break;
    }
    NSLog(selType);
    // Display selection resize elements if they are hidden, and hide them if they are displayed
    BOOL isBallonsHidden = [selectionArea valueForKey:@"m_isBallonsHidden"];
    if(isBallonsHidden){
        [selectionArea showBalloons];
    }
    else{
        [selectionArea hideBalloons];
    }
}

Select table cell by pressing it. As a result, the table cell is selected, selection area resize elements are displayed, and also table background color is changed:

The development environment console also displays information about the selected area:

Table selected area size: (80.000000, 50.000000)

Table selected area position: (240.000000, 150.000000)

Selection area is empty: 0

Selected area is being changed at the moment: 0

Number of selected elements: 0

Selection area type: area is missing

See also:

Examples of Component Use