Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes implementation of cell highlighting. After starting the example the following operations are executed:
Text font parameters in the highlighted cell are set and removed.
Fill color in the highlighted cell is set and removed.
Text in the highlighted cell is set and removed.
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 { // Get table formatting theme NuGridTheme *theme = [proxyDatasource gridViewTheme:[contr gridView]]; // Get default style for all cells except for headers NuGridCellStyle *style = [theme defaultStyle]; // Determine text font parameters in highlighted cell [style setHighlightFont:[UIFont fontWithName:@"Courier New" size:20]]; // Determine fill color in highlighted cell [style setHighlightBackgroundColor:[UIColor blueColor]]; // Determine text color in highlighted cell [style setHighlightTextColor:[UIColor whiteColor]]; }; // Determines whether to enable cell highlighting on the cell touch -(BOOL) gridView:(NuGridView *)gridView cellShouldHighlightOnTouchDown:(NuGridCell *)cell { if ([cell isRowHeader] | [cell isColumnHeader]) { // Remove highlighting of all table cells return NO; } else { // Enable highlighting of all cells that are not headers return YES; } } // Determines whether to enable highlighting of cell with expander on the cell touch -(BOOL) gridView:(NuGridView *)gridView cellShouldHighlightOnExpanderTouchDown:(NuGridCell *)cell { return [self gridView:gridView cellShouldHighlightOnTouchDown:cell]; } // Handles double touch on table cell - (void)gridView:(NuGridView *)gridView wasDoubleTouchedInCell:(NuGridCell *)cell { if ([self gridView:gridView cellShouldHighlightOnExpanderTouchDown:cell]) { [cell setIsHighLighted:![cell isHighLighted]]; if ([cell isHighLighted]) { // Fill cell background with appropriate color [cell setBackgroundColor:[[cell style] highlightBackgroundColor]]; } else { // Apply default style NuGridCellStyle *style = [proxyDatasource gridViewGetDefaultStyle:[contr gridView]]; [cell setBackgroundColor:[style backgroundColor]]; } } else { // On selecting table header remove highlighting of all cells NuGridCellStyle *style = [proxyDatasource gridViewGetDefaultStyle:[contr gridView]]; [proxyDatasource gridView:[contr gridView] setStyle:style forRow:[cell rowNumber]]; } } // Handles double touch on table column -(void)gridView:(NuGridView *)gridView wasDoubleTouchedInColumn:(NuGridColumn *)column { NSLog(@"Cell is selected in the %d column", [column columnNumber]); } // Handles double touch on table row -(void)gridView:(NuGridView *)gridView wasDoubleTouchedInRow:(NuGridRow *)row { NSLog(@"Cell is selected in the %d row", [row rowNumber]); }
After executing the example the Courier New text font, blue color fill and white text color are set for the cells that are not headers on double touch:
The development environment console displays information, which cell is touched:
A cell in the column 1 is selected
A cell is the row 1 is selected
After repeated double touch this cell is restored to its initial view: The double touch of row or column header removes highlighting of all table cells:
Then remove text font, fill and text color parameters for all highlighted table cells by adding the following strings to the executeExample method:
// Remove fill color in highlighted cell [style removeHighlightBackgroundColor]; // Remove font parameters in highlighted cell [style removeHighlightFont]; // Remove text color in highlighted cell [style removeHighlightTextColor];
After executing the example the determined settings are removed from highlighted cells. Now the cell selected by the double touch has black fill and text color:
See also: