Selecting Table Area

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes selecting of table area. After starting the example the following operations are executed:

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 selection
    [contr setCanSelect:YES];
    [[contr gridView] setCanSelect:[contr canSelect]];
    // Select table area
    NuGridView *gridView = [contr gridView];
    [contr selectAreaFromRow:[gridView rowWithNumber:1] column:[gridView columnWithNumber:1]
    toRow:[gridView rowWithNumber:2] column:[gridView columnWithNumber:2]];
};
// Called after table area is selected
- (void)gridView:(NuGridView *)gridView areaSelected:(NuGridSelectionArea *)area
{
    // Determine label position and size
    CGRect rect = [area bounds];
    CGPoint position = [area center];
    rect.origin.x = position.x - rect.size.width/2;
    rect.origin.y = position.y - rect.size.height/2;
    // Create a label
    [self showViewWithText:@"Area selected" inRect:rect];
}
-(void)showViewWithText:(NSString*)text inRect:(CGRect)rect {
    UILabel *label = [[UILabel new] autorelease];
    label.textColor = [UIColor redColor];
    [label setText:text];
    // Align text by center
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setFrame: rect];
    // Display label
    [[contr gridView] addSubview:label];
}
// Removes displayed element
- (void)hideView:(UIView *)view {
    [view removeFromSuperview];
}
// Called before table layout change
- (void)gridViewActionBeforeLaying:(NuGridView *)gridView {
    if([gridView canSelect]) {
        // Display label with message about table area selection
        [self gridView:gridView areaSelected:[gridView selectionArea]];
        [gridView setCanSelect:NO];
    }
}
// Called after table layout change
- (void)gridViewActionAfterLaying:(NuGridView *)gridView {
    for (UIView *view in [gridView subviews]) {
        if([view isKindOfClass:[UILabel class]]) {
            // Hide all labels in three seconds
            [self performSelector:@selector(hideView:) withObject:view afterDelay:3.0];
        }
    }
}

After executing the example the table cell range is selected that covers rows and columns having the numbers 1 and 2. A text label aligned by center and informing about cell selection is displayed above the selection:

This text disappears in three seconds, table cell selection remains:

See also:

Examples of Component Use