Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind rows NSRuleEditor with array

In developer documentation i found this:

NSRuleEditor exposes one binding, rows. You can bind rows to an ordered collection (such as an instance of NSMutableArray). Each object in the collection should have the following properties:

  • @"rowType" An integer representing the type of the row(NSRuleEditorRowType).

  • @"subrows" An ordered to-many relation (such as an instance of NSMutableArray) containing the directly nested subrows for the given row.

  • @"displayValues" An ordered to-many relation containing the display values for the row.

  • @"criteria" An ordered to-many relation containing the criteria for the row.

Anybody may give an example how to do this?

like image 750
Nikolai Nagornyi Avatar asked Jan 31 '12 15:01

Nikolai Nagornyi


1 Answers

=========== EDIT =============

As I researched, the NSRuleEditor class header contains the next documentation about binding:

* -- Bindings support -- */

/* Sets the class used when creating a new row in the "rows" binding; this class should be KVC and KVO compliant for the key paths listed below.  By default this is NSMutableDictionary */
- (void)setRowClass:(Class)rowClass;
- (Class)rowClass;

/* Set and get the key path for the row type, which is used to get the row type in the "rows" binding.  The row type is a value property of type NSRuleEditorRowType.  The default is @"rowType". */
- (void)setRowTypeKeyPath:(NSString *)keyPath;
- (NSString *)rowTypeKeyPath;

/* Set and get the key path for the subrows, which is used to determined nested rows in the "rows" binding.  The subrows property is an ordered to-many relationship containing additional bound row objects. The default is @"subrows". */
- (void)setSubrowsKeyPath:(NSString *)keyPath;
- (NSString *)subrowsKeyPath;

/* Set and get the criteria key path, which determines the criteria for a row in the "rows" binding.  (The criteria objects are what the delegate returns from - ruleEditor: child: forCriterion: withRowType:).  The criteria property is an ordered to-many relationship. The default is @"criteria". */
- (void)setCriteriaKeyPath:(NSString *)keyPath;
- (NSString *)criteriaKeyPath;

/* Set and get the display values key path, which determines the display values for a row (the display values are what the delegate returns from - ruleEditor: displayValueForCriterion: inRow:).  The criteria property is an ordered to-many relationship. The default is @"displayValues". */
- (void)setDisplayValuesKeyPath:(NSString *)keyPath;
- (NSString *)displayValuesKeyPath;

And to expand the answer, I am giving the next example so you'll understand how to bind your own class as rows:

@interface BindObject : NSObject

@property (nonatomic, assign) NSInteger rowType;
@property (nonatomic, strong) NSMutableArray *subrows;
@property (nonatomic, strong) NSMutableArray *displayValues;
@property (nonatomic, strong) NSMutableArray *criteria;

@end

// binding custom class as row class
[self.ruleEditor setRowClass:[BindObject class]];

Now as you add new rows to NSRuleEditor your class will be used. You also can change KeyPath so fields (ivars/properties) in your custom row class may be called differently than it's speicifed in documentation.

Hope this will help you to understand how NSRuleEditor works.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

I've found this article, it should help you understand how NSRuleEditor works.

like image 108
art-divin Avatar answered Sep 27 '22 15:09

art-divin