Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example implements setting of new style with changed font for table data source.
The development environment console also displays table row height value. Pressing the table cell gradually selects the row and column, which contain the cell, and displays the selected area size value, after that the selection is cleared. The development environment console also displays values of the cell row and column, positions of row and column headers, and value of the obtained cell.
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 NuGridView *gridView = [contr gridView]; // Get object that is used to work with table ViewController *viewContr = [gridView gridDelegate]; // Display table row height NSInteger rHeight = [viewContr gridView:(NuGridView *)gridView heightForRow:0]; NSLog(@"%@ %d", @"Table row height:", rHeight); // Determine style NuGridCellStyle *cellStyle = [NuGridCellStyle deafultStyle]; // Remove images used by collapsed and expanded expander [cellStyle removeExpandedImage]; [cellStyle removeCollapsedImage]; [cellStyle setExpanderImageMargin:0]; // Set new font [cellStyle setFont:[UIFont fontWithName:@"Arial" size:25]]; // Get data source ProxyDataSource *dataSource = [gridView dataSource]; // Change default style [dataSource gridView:(NuGridView *)gridView setDefaultStyle:cellStyle]; // Refresh cell sizes [gridView contentSizeUpdated]; // Refresh table [gridView dataSourceUpdated]; }; // Handle table cell press event - (void)gridView:(NuGridView *)gridView wasTouchedInCell:(NuGridCell *)cell { // Enable table cell selection if(![gridView canSelect]){ [[gridView controller] setCanSelect:YES]; } // Select column with pressed cell [[gridView controller] selectColumnByCell:cell]; // Get column selection area if it is selected, and display its sizes if([[gridView controller] isColumnWithNumberSelected:[cell columnNumber]]) { NuGridSelectionArea *colSelArea = [gridView selectionAreaForColumnNumber:[cell columnNumber]]; NSLog(@"%@ (%f, %f)", @"Column selection area size:", [colSelArea originFrame].size.width, [colSelArea originFrame].size.height); // Remove selection [[gridView controller] deselectColumnByCell:cell]; } // Select row with pressed cell [[gridView controller] selectRowByCell:cell]; // Get row selection area if it is selected, and display its sizes if([[gridView controller] isRowWithNumberSelected:[cell rowNumber]]) { NuGridSelectionArea *rowSelArea = [gridView selectionAreaForRowNumber:[cell rowNumber]]; NSLog(@"%@ (%f, %f)", @"Row selection area size:", [rowSelArea originFrame].size.width, [rowSelArea originFrame].size.height); // Remove selection [[gridView controller] deselectRowByCell:cell]; } // Disable table cell selection [[gridView controller] setCanSelect:NO]; // Get row and column with cell NuGridRow *row = [gridView rowWithNumber:[cell rowNumber]]; NuGridColumn *col = [gridView columnWithNumber:[cell columnNumber]]; // Display row and column positions NSLog(@"%@ %f",@"Cell column position:", [col xPosition]); NSLog(@"%@ %f",@"Cell row position:", [row yPosition]); // Get cell header row and column NuGridColumn *colHeader = [gridView headerColumnWithNumber: [cell columnNumber]]; NuGridRow *rowHeader = [gridView headerRowWithNumber: [cell rowNumber]]; // Display cell header row and column positions NSLog(@"%@ %f",@"Cell header column position:", [colHeader xPosition]); NSLog(@"%@ %f",@"Cell header row position:", [rowHeader yPosition]); // Get cell with specified column and row and display its value NuTextGridCell *textCell = [gridView cellInRow:[cell rowNumber] column:[cell columnNumber]]; NSLog(@"%@ %@", @"Value of obtained cell:", [textCell value]); }
As a result, table data source style is changed:
Press the E4 table cell. As a result, the development environment console displays information about the table, about selected area and the obtained cell:
Table row height: 50
Column selection area size: (80.000000, 250.000000)
Row selection area size: (400.000000, 50.000000)
Cell column position: 373.000000
Cell row position: 233.000000
Cell header column position: 212.000000
Cell header row position: 132.000000
Value of obtained cell: 8
See also: