Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
The main method of the example implements changing of table cell background color and displaying the calculated size of specified cell into the development environment console. The example handles touch event for the table cell, for which the following operations are executed:
Border highlighting and width are set.
Information about merged rows and columns if they exist is cleared.
The development environment console also displays the following information:
Index of the cell rows and column, if the cell is in the merged cell.
Repeated use identifier.
Cell size and its string view.
Values of absolute position and table visible area positions for the column and row, to which the cell belongs.
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 cell NuGridCell *cell = [proxyDatasource gridView:(NuGridView *)[contr gridView] cellInRow:1 inColumn:1]; // Get cell style NuGridCellStyle *style = [cell style]; // Change background cell color [style setBackgroundColor:[UIColor grayColor]]; // Calculate and display cell size based on its contents CGSize size = [cell bestSize]; NSLog(@"%@ (%f, %f)", @"Calculated cell size:", size.width, size.height); }; // Handle table cell press event - (void)gridView:(NuGridView *)gridView wasTouchedInCell:(NuGridDecoratedCell *)cell { // Set cell highlighting [cell setIsHighLighted:YES];
// Set cell border width
[cell setBorderWidth:2]; // Get number of columnes and rows belonging to merged cell NSInteger includedColumnsCount = [[cell includedColumns ]count]; NSInteger includedRowsCount = [[cell includedRows] count]; // Clear information about merged rows and columns if they exist if((includedColumnsCount != 0) && (includedRowsCount != 0)) { [cell clearIncludes]; } // If cell is included into merged cell, display indexes of its row and column if([cell isLink]) { NSLog(@"%@ %d", @"Column index:", [cell linkColumn]); NSLog(@"%@ %d", @"Row index:", [cell linkRow]); } // Display reuse identifier NSLog(@"%@ %@", @"Reuse identifier:", [cell reuseIdentifier]); // Display cell size NSLog(@"%@ (%f, %f)", @"Cell size:", [cell width], [cell height]); // Display string view of cell data NSLog(@"%@ %@", @"String view of cell data:", [cell toString]); // Get column with a cell NuGridColumn *col = [cell column]; // Display absolute column position along the X axis NSLog(@"%@ %f", @"Absolute column position along the X axis:", col.absoluteXPosition); // Display column position along the X axis in table visible area NSLog(@"%@ %f", @"Column position along the X axis in table visible area:", col.xPosition); // Get row with a cell NuGridRow *row = [cell row]; // Display absolute row position along the Y axis NSLog(@"%@ %f", @"Absolute row position along the Y axis:", row.absoluteYPosition); // Display row position along the Y axis in table visible area NSLog(@"%@ %f", @"Row position along the Y axis in table visible area:", row.yPosition); };
After executing the example cell background color is changed, the development environment console displays the calculated size of obtained cell:
Calculated size of cell: (7.980000, 16.702000)
After pressing any table cell it is highlighted, and width of its borders is changed:
The development console also displays information about the pressed cell:
Repeated use identifier: row
Cell size: (80.000000, 50.000000)
String view of cell data: 2
Absolute position of column on X axis: 133.000000
Position of column on X axis in table visible area: 133.000000
Absolute position of row on Y axis: 83.000000
Position of row on Y axis in table visible area: 83.000000
See also: