Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes table conditional formatting setup based on the rule "Value between A and B". Helpers that work with the whole table are used to determine rule properties and rule-based conditional formatting settings.
Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Express Report section):
MAExpressAnalysisReportViewController *contr = (MAExpressAnalysisReportViewController *)m_controller; // Get array of data view controllers NSArray *controllers =[contr dataViewControllers]; // Determine values of A and B double valueA = 7000; double valueB = 8000; // Parse data view controllers in cycle for(NSObject *controller in controllers) { // Check if the current controller is a table data view controller if([controller isMemberOfClass:[MAGridDataViewController class]]) { // Get table data view controller object MAGridDataViewController *gridController = (MAGridDataViewController *)controller; // Get controller view UIView *view = [gridController view]; // Get array of subviews NSArray *subviews = [view subviews]; // Parse subviews in cycle for(NSObject *subview in subviews) { // Check if the current view is a table view if([subview isMemberOfClass:[NuGridView class]]) { // Get table view object NuGridView *gridView = (NuGridView *)subview; // Get table delegate MAGridDelegate *delegate = (MAGridDelegate*)[gridView gridDelegate]; // Get proxy data source MAGridProxyDataSource *proxyDatasource = (MAGridProxyDataSource*)[delegate proxyDataSource]; // Create a conditional formatting rule MAConditionalFormattingRule *formattingRule = [[MAConditionalFormattingRule new] autorelease]; // Set type of the rule "Value between A and B" [formattingRule setType: kCFRTBetween]; // Create a helper that works with the whole table to determine rule properties MAConditionalFormattingRuleGlobalHelper *ruleGlobalHelper = [[MAConditionalFormattingRuleGlobalHelper new] autorelease]; // Get rule settings as a dictionary NSMutableDictionary *ruleSettings = (NSMutableDictionary*)[ruleGlobalHelper gridSettingsDictionaryFrom: formattingRule]; // Set fill color for cells that satisfy the rule [ruleSettings setValue: [UIColor colorWithRed:1 green:0.77 blue:0.27 alpha:1] forKey:@"kGridRulesABColor"]; // Mark created rule as active [ruleSettings setValue:[NSNumber numberWithBool: YES] forKey: @"kGridRulesAB"]; // Load conditional formatting rule settings from dictionary [ruleGlobalHelper setupRule:formattingRule fromGridSettingsDictionary:ruleSettings]; // Initialize rule-based conditional formatting settings MAConditionalFormattingRules *rules = [[MAConditionalFormattingRules new] autorelease]; // Get the rule "Value between A and B" MAConditionalFormattingRule *betweenRule = [rules ruleByType: [formattingRule type]]; // Merge rules [betweenRule merge: formattingRule]; /* To determine rule-based conditional formatting settings, create a helper that works with the whole table */ MAConditionalFormattingRulesGlobalHelper *rulesGlobalHelper = [[MAConditionalFormattingRulesGlobalHelper new] autorelease]; // Get rule-based conditional formatting settings as a dictionary NSMutableDictionary *rulesSettings = (NSMutableDictionary*)[rulesGlobalHelper gridSettingsDictionaryFrom: rules]; // Set values of A and B [rulesSettings setValue:[NSNumber numberWithDouble: valueA] forKey:@"kGridRulesABValueA"]; [rulesSettings setValue:[NSNumber numberWithDouble: valueB] forKey:@"kGridRulesABValueB"]; // Get conditional formatting settings from dictionary rules = [rulesGlobalHelper setupFromGridSettingsDictionary: rulesSettings]; // Create a basic helper for working with conditional formatting settings MAConditionalFormattingHelper *formattingHelper = [[MAConditionalFormattingHelper alloc] initWithProxyDataSource: proxyDatasource]; // Apply conditional formatting settings to the whole table [formattingHelper applyGlobalConditionalFormat: rules]; } } } }
After executing the example the conditional formatting with the use of the rule "Cells between A and B" is applied to the express report whole table. All the cells containing values from 7000 to 8000 are filled with yellow color:
See also: